I’m having a jQuery issue which is making debugging JavaScript more of a bitch than it already is: statements inside of a jqXHR deferred function will fail silently if they fail, and I haven’t found a way to capture this error. Consider the following example:
var xhr = $.ajax({type: "GET",
url: "test.php"});
xhr.done(function() {
a += b;
});
Where a and b are both undefined. This should return an error, but instead all execution stops and I get no notice that anything has failed. If, on the other hand, I write the following:
function thisIsAnError() {
a += b;
}
thisIsAnError();
it will fail as expected, logging “a is not defined” to both the Firefox error console and the Firebug console.
A Google search turned up nothing, perhaps there is some error-handling function in jQuery I’ve missed? Note that xhr.fail() does not capture this error because it wasn’t the XHR that failed.
The
$.get()function you are using has nodone()method. I believe what you’re wanting to attach your function to is thesuccess()method. jsFiddle exmample of it working.http://api.jquery.com/jQuery.get/
http://api.jquery.com/jQuery.get/#jqxhr-object