I have been trying to setup custom ajaxTransports for jQuery to short-circuit some workflows in certain scenarios for our product. However, I have had zero success in getting these transports to be honored (whereas I have many working custom ajaxPrefilters).
Tested with multiple versions of jQuery:
Tested with multiple browsers:
...
None of them worked.
JsFiddle test case: http://jsfiddle.net/PVYut/
...
If I add a dataType
to narrow it down, then it works fine.
JsFiddle test case: http://jsfiddle.net/PVYut/1/
...
Am I just doing something all wrong? I'd be happy to be told so, so long as I can get this working! -_-
$.ajaxTransport("+*", function(options, originalOptions, jqXHR, headers, completeCallback ) {
console.log("Executing ajaxTransport");
return {
send: function( headers, completeCallback ) {
completeCallback(404, "error", {});
},
abort: function() {
/* abort code */
}
}
});
$.ajax("?jqTrans=" + (+(new Date())))
.done(function() {
console.log("ERROR: Should not have been successful!");
})
.fail(function() {
console.log("SUCCESS: Should have failed.");
});
Here is jsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With