jQuery.ajaxTransport(dataType, handler) (since 1.5) registers a factory that can return a transport object with send and abort. jQuery uses that object to transmit the request for the given dataType.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$.ajaxTransport(dataType, function (options, originalOptions, jqXHR) {
if (/* can handle */) {
return {
send: function (headers, completeCallback) { /* transmit */ },
abort: function () { /* cancel */ }
};
}
// return undefined → jQuery tries another transport
});
// Pipeline: ajaxSetup → ajaxPrefilter → transport.send → completeCallback
Call
What it does
dataType
Which requests ask this factory first
factory
function(options, originalOptions, jqXHR)
send
function(headers, completeCallback)
abort
Cancel in-flight work; ignore late callbacks
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Call $.ajaxTransport("yourType", factory) once at bootstrap.
Step 2
Inside the factory, inspect options (and optionally originalOptions, jqXHR).
Step 3
If you can handle it, return { send, abort }; otherwise return nothing.
Return Value
Return Value
Description
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Factory Skeleton
Return a transport only when you can handle the request; otherwise fall through.
jQuery
$.ajaxTransport("demo", function (options) {
if (options.type === "GET" && options.url.indexOf("demo://") === 0) {
return {
send: function (headers, completeCallback) {
var payload = options.url.replace("demo://", "");
completeCallback(200, "success", {
demo: "Demo says: " + payload
});
},
abort: function () {}
};
}
});
$("#run").on("click", function () {
$.ajax({
url: "demo://Hello transport",
dataType: "demo"
}).done(function (text) {
$("#log").text(text);
});
});
jQuery.ajaxTransport(dataType, handler) registers a factory that jQuery calls when selecting how to transmit a request for that dataType. If the factory can handle the call, it returns an object with send and abort. Otherwise it returns undefined and jQuery tries another transport. This is the lowest-level Ajax extension point.
send(headers, completeCallback) starts transmission and must eventually call completeCallback when finished. abort() cancels an in-flight request — clear timers, detach Image handlers, or ignore late callbacks so completeCallback does not fire after cancel.
On jQuery 3.7 (common in tutorials), use the positional form: completeCallback(status, statusText, responses, headers). status is like 200 or 404; statusText is "success" or "error"; responses maps dataType keys to values (for example { image: imgElement }); headers is an optional response-header string. Newer jQuery versions also accept a single params object.
ajaxPrefilter runs earlier to tweak options (url, headers, cache) or abort. ajaxTransport replaces how bytes are sent and received for matching dataTypes. Prefer prefilters for option changes; use transports only when prefilters and converters are not enough.
As a last resort: custom protocols, Image-based loads, in-memory mocks, or non-HTTP sources. For ordinary JSON, HTML, or script requests, built-in $.ajax() transports already work — do not register a custom transport.
Each request needs its own transport instance with isolated state (timers, Image nodes, sockets). Registering one shared object would let concurrent requests clobber each other. The factory returns a fresh { send, abort } per matching request.