Looking at the jQuery source code, this is all $.getJSON
does:
getJSON: function( url, data, callback ) {
return jQuery.get(url, data, callback, "json");
},
And this is all $.get
does:
get: function( url, data, callback, type ) {
// shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
callback = data;
data = null;
}
return jQuery.ajax({
type: "GET",
url: url,
data: data,
success: callback,
dataType: type
});
},
No black magic there. Since you need to customize stuff other than the basic $.getJSON
functionality, you can just use the low-level $.ajax
function and pass the async option as false:
$.ajax({
type: 'GET',
url: 'whatever',
dataType: 'json',
success: function() { },
data: {},
async: false
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…