jQuery.ajaxTransport()The jQuery.ajaxTransport() method in jQuery is used to creates an object that handles the actual transmission of Ajax data.
jQuery.ajaxTransport() syntaxjQuery.ajaxTransport(dataType,hanlder)
dataType is a string identifying the data type to use.
handler is a handler to return the new transport object to use.
jQuery.ajaxTransport() exampletransports a minimal image
$.ajaxTransport( "image", function( s ) {
if ( s.type === "GET" && s.async ) {
var image;
return {
send: function( _ , callback ) {
image = new Image();
function done( status ) {
if ( image ) {
var statusText = ( status === 200 ) ? "success" : "error",
tmp = image;
image = image.onreadystatechange = image.onerror = image.onload = null;
callback( status, statusText, { image: tmp } );
}
}
image.onreadystatechange = image.onload = function() {
done( 200 );
};
image.onerror = function() {
done( 404 );
};
image.src = s.url;
},
abort: function() {
if ( image ) {
image = image.onreadystatechange = image.onerror = image.onload = null;
}
}
};
}
});
