[英]What does this code mean? $.getJSON
i know this: 我知道这个:
$.getJSON(
"test.js",
function(json){
alert("JSON Data: " + json.users[3].name);
}
);
but i see the code in a site: 但我在网站上看到了代码:
$.getJSON(l, {
tag: "userName",
userName: 'sss'
}
what is '1' mean,in this place. 在这个地方,“ 1”是什么意思。
thanks 谢谢
If you copy/pasted, then that's actually an "L", not a one. 如果您复制/粘贴,则实际上是一个“ L”,而不是一个。 "
l
" is probably a variable containing a URL/filename. “
l
”可能是一个包含URL /文件名的变量。
That actually might be a variable: 那实际上可能是一个变量:
$(function(){
var l = "getJSON.php";
$.getJSON(l, { 'data':'foo' }, function(data) {
alert(data);
});
});
...quite honestly, it looks like bad code. ...说真的,这看起来像是错误的代码。 According to the jQuery API browser , argument one should be a URL, not a number.
根据jQuery API浏览器 ,参数1应该是URL,而不是数字。 Does the code sample function?
代码示例是否起作用?
EDIT : Just checked; 编辑 :刚刚检查; it does not.
它不是。 That code sample does nothing.
该代码示例不执行任何操作。
The first argument is an l
(as in letter), not a 1
(as in 1 font you should probably avoid), and is a URL. 第一个参数是
l
(如字母),而不是1
(如应避免使用1字体),并且是URL。
The second argument is an object containing data to be sent with the request. 第二个参数是一个对象,其中包含要与请求一起发送的数据。
jQuery.ajax()
defaults to a GET
request, so that data will be parameterized and added to the URL as tag=userName&userName=sss
jQuery.ajax()
默认为GET
请求,因此数据将被参数化并以tag=userName&userName=sss
添加到URL
More info here: http://api.jquery.com/jQuery.ajax/ 此处提供更多信息: http : //api.jquery.com/jQuery.ajax/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.