Created
August 17, 2012 12:25
-
-
Save cowboy/3378441 to your computer and use it in GitHub Desktop.
jQuery: How can I create a catch-all Ajax transport?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When I set up a json-specific transport... | |
$.ajaxTransport("json", function(options) { | |
console.log("json", options); | |
}); | |
// The json options are logged. | |
$.getJSON("/foo"); | |
// When I try to set up a catch-all transport... | |
$.ajaxTransport("*", function(options) { | |
console.log("catch-all", options); | |
}); | |
// Nothing is logged. The transport factory function doesn't execute. | |
$.ajax("/foo"); |
Thanks! I must have missed the +
in the docs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You want to place your transport in front of all the existing ones, or else, a transport will be selected before you got a chance to give yourse. Hence the use of
+
in front of the dataType selector.Same goes for prefilters, even if order is a bit less important there.