javascript - jQuery 中的 AJAX 调用,什么定义了 "json"作为参数?

标签 javascript jquery ajax

我找到了这行代码。此 AJAX 调用的最后一个参数是字符串“json”。

它代表什么?

$.get(theUrl, function(e) {
    make(e);
  }, "json")

最佳答案

这意味着ajax将返回数据类型 json

数据类型:(例如:xml、json、脚本或 html)

The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback).

<小时/>

"json": Evaluates the response as JSON and returns a JavaScript object. The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of null or {} instead. (See json.org for more information on proper JSON formatting.)

关于javascript - jQuery 中的 AJAX 调用,什么定义了 "json"作为参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21812491/

相关文章:

javascript - Safari 不使用 window.location.href 打开 href

JavaScript 变形按钮

javascript - 弹出模态 FB 喜欢

javascript - 带有 html 5 的元素上的自定义表单验证功能

ajax - firefox中的跨域ajax

javascript - 在 Three.js 中旋转球体,以便地球仪的映射图像与 Three.js 中也显示的 GeoJSON 相匹配

javascript - 有没有简单的方法可以找到 jQuery 代码的 "javascript equivalent"?

php - 如何接收 jQuery AJAX 响应中的错误?

javascript - 如何在 C# 通用处理程序中引用从 javascript 接收的反序列化对象属性?

javascript - Axios 发布表单数据在 native react 中无法正常工作