jQuery detects the callback=?
part of your URL and automatically switches the dataType from 'json'
to 'jsonp'
.
JSONP is a JSON query that is not made using XMLHttpRequest but by adding a script tag to your page. Calling back into your script is handled by the caller giving the name of a JavaScript function to execute when the script loads. This is why cross-domain is working.
jQuery will handle JSONP transparently for you in a $.ajax request. The manual (and to me cleaner) way to do this is to define a 'jsonp'
dataType and use the placeholder ?
for the callback name in the URL. jQuery will automatically replace the ?
with an appropriate value to trigger your success callback.
$.ajax(
{
url : "http://api.twitter.com/1/users/show/google.json&jsoncallback=?",
dataType : 'jsonp',
success : function(data)
{
alert(data.results.length);
}
});