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://codercto.com/courses/l/35.html

查看所有标签

New Dark Age

New Dark Age

James Bridle / Verso Books / 2018-7-17 / GBP 16.99

As the world around us increases in technological complexity, our understanding of it diminishes. Underlying this trend is a single idea: the belief that our existence is understandable through comput......一起来看看 《New Dark Age》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具