I'm confused about the "clean" way to call $.getJSON
.
According to the documentation, the synopsis is:
jQuery.getJSON( url [, data ] [, success ] )
where data
is "a plain object or string that is sent to the server with the request", and success
is "a callback function that is executed if the request succeeds".
In my experience, the data
argument is often not needed in practice, in which case I call $.getJSON
as
$.getJSON( some_url, {}, function(response) { /* do something */ });
That is, I simply pass an empty object as data
. However, I've also seen people use
$.getJSON( some_url, function(response) { /* do something */ });
This is confusing, since it looks like the callback function is being passed as the data
object. Yet it seems to work just fine.
How come this works? Is jQuery "clever" enough to understand the second syntax, even though it doesn't strictly correspond to the specification? Is there effectively some difference in what happens in those two calls? Between the two, is there a preferred way?