views:

76

answers:

4

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.

thanks

A: 

That actually might be a variable:

$(function(){
  var l = "getJSON.php";
  $.getJSON(l, { 'data':'foo' }, function(data) {
    alert(data);
  });
});
Jonathan Sampson
But if the user is on an HTML page, why is it getting the same page as JSON?
Matchu
A: 

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

Matchu
Note that the OP doesn't actually post the closing `)` of the function call, so as far as we know, there may well be a callback that the OP left out. *(I doubt it, but since he's leaving stuff out...)*
Atli
+4  A: 

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

jimyi
Nice catch. This confusion seems to be just about bad formatting. I see nothing wrong with the code, really. - *(This is why we don't use single letters as variable names. Programmers != mathematicians! :D)*
Atli
A: 

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/

Ryan Graham