$.getJSON()
is a kind of abstraction of a regular AJAX call where you would have to tell that you want a JSON encoded response.
$.ajax({
url: url,
dataType: 'json',
data: data,
success: callback
});
You can handle errors in two ways: generically (by configuring your AJAX calls before actually calling them) or specifically (with method chain).
'generic' would be something like:
$.ajaxSetup({
"error":function() { alert("error"); }
});
And the 'specific' way:
$.getJSON("example.json", function() {
alert("success");
})
.done(function() { alert("second success"); })
.fail(function() { alert("error"); })
.always(function() { alert("complete"); });
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…