How can you handle errors in a getJSON call? Im trying to reference a cross-domain script service using jsonp, how do you register an error method?
Why not
getJSON('get.php',{cmd:"1", typeID:$('#typesSelect')},function(data) {
// ...
});
function getJSON(url,params,callback) {
return $.getJSON(url,params,callback)
.fail(function(jqXMLHttpRequest,textStatus,errorThrown) {
console.dir(jqXMLHttpRequest);
alert('Ajax data request failed: "'+textStatus+':'+errorThrown+'" - see javascript console for details.');
})
}
??
For details on the used .fail() method (jQuery 1.5+), see http://api.jquery.com/jQuery.ajax/#jqXHR
Since the jqXHR is returned by the function, a chaining like
$.when(getJSON(...)).then(function() { ... });
is possible.