jQuery getJSON() 方法

jQuery 教程 · 2019-03-28 13:39:02

实例

使用 Ajax 请求获取 JSON 数据,并输出结果:

$(document).ready(function(){ $("button").click(function(){ $.getJSON("demo_ajax_json.js",function(result){ $.each(result, function(i, field){ $("div").append(field + " "); }); }); }); });

定义和用法

getJSON() 方法使用 AJAX 的 HTTP GET 请求获取 JSON 数据。

语法

$(selector).getJSON(url,data,success(data,status,xhr))

参数 描述
url 必需。规定将请求发送到哪个 URL。
data 可选。规定发送到服务器的数据。
success(data,status,xhr) 可选。规定当请求成功时运行的函数。
额外的参数:
  • data - 包含从服务器返回的数据
  • status - 包含请求的状态("success"、"notmodified"、"error"、"timeout"、"parsererror")
  • xhr - 包含 XMLHttpRequest 对象

点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html

查看所有标签

HTTP

HTTP

David Gourley、Brian Totty、Marjorie Sayer、Anshu Aggarwal、Sailu Reddy / O'Reilly Media / 2002-10-7 / USD 54.99

Product Description Web technology has become the foundation for all sorts of critical networked applications and far-reaching methods of data exchange, and beneath it all is a fundamental protocol......一起来看看 《HTTP》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具