jQuery.AJAX and the "always" callback

This effects some of the JavaScript work-around code we have in circulation, especially the GeoLocation code (from memory). I've found (and officially complained about: http://bugs.jquery.com/ticket/11548) the way AJAX works in jQuery.

If your code combines $.get / $.load / $.post / $.ajax with an ".always" function, then you'll probably need to compensate for this issue. Basically, the order of the ".always" parameters is different depending on if the AJAX request failed or succeeded, meaning the code we have in circulation only behaves as expected when the request is successful.

You probably have something like:

$.ajax('http://my.url/request.php')
.always(function(response, status, jqxhr) {
 // your code here
});
What you need to do is swap the 1st and 3rd parameters around in case of error, like so:
$.ajax('http://my.url/request.php')
.always(function(response, status, jqxhr) {
 var swap;
 if (!jqxhr || $.type(jqxhr.promise) !== 'function') {
   swap = jqxhr;
   jqxhr = response;
   response = swap;
 }
 // your code here
});
If you don't apply this fix, then your code might not behave the way you want it to in case of error (especially if you test the 1st or 3rd parameters to decide if you have an error). That's probably okay, but it's just something to bear in mind. Ron Waldon