开发者

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' mea开发者_运维百科n,in this place.

thanks


If you copy/pasted, then that's actually an "L", not a one. "l" is probably a variable containing a URL/filename.


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. 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.

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

More info here: http://api.jquery.com/jQuery.ajax/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜