jQuery Tutorial Tutorials - jQuery.ajaxTransport()

jQuery jQuery.ajaxTransport()

The jQuery.ajaxTransport() method in jQuery is used to creates an object that handles the actual transmission of Ajax data.

jQuery jQuery.ajaxTransport() syntax

jQuery.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 jQuery.ajaxTransport() example

example

transports 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;
        }
      }
    };
  }
});
Date:2019-08-30 02:55:19 From:www.Lautturi.com author:Lautturi