jQuery(function($) { // Shorter for $(document).ready(function() {, and you make sure that $ refers to jQuery.
$.ajax({ // All jQuery ajax calls go throw here. $.getJSON is just a rewrite function for $.ajax
url: "https://api.twitter.com/1/users/show.json?screen_name=TwitterAPI&include_entities=true",
dataType: "jsonp", // dataType set to jsonp (important)
success: function( resp ) {
console.log( resp ); // Here resp represents the data reseved from the ajax call.
}
});
});
jQuery source code:
$.getJSON = function( url, data, callback ) {
return jQuery.get( url, data, callback, "json" );
}
Redirect you to $.get
jQuery.each( [ "get", "post" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
// shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}
return jQuery.ajax({
type: method,
url: url,
data: data,
success: callback,
dataType: type
});
};
});
Ass you can see this returns a initialized version of $.ajax
So your call rewrites to:
$.ajax({
url: "...",
dataType: "json" // <- Note json not jsonp,
success: function() {
// ...
}
});
&callback=?
:$.getJSON("https://api.twitter.com/1/users/show.json?screen_name=TwitterAPI&include_entities=true&callback=?",function(data)