A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://api.jquery.com/jQuery.ajaxTransport/ below:

jQuery.ajaxTransport() | jQuery API Documentation

jQuery.ajaxTransport( dataType, handler )Returns: undefined

Description: Creates an object that handles the actual transmission of Ajax data.

A transport is an object that provides two methods, send and abort, that are used internally by $.ajax() to issue requests. A transport is the most advanced way to enhance $.ajax() and should be used only as a last resort when prefilters and converters are insufficient.

Since each request requires its own transport object instance, transports cannot be registered directly. Therefore, you should provide a function that returns a transport instead.

Transports factories are registered using $.ajaxTransport(). A typical registration looks like this:

1

2

3

4

5

6

7

8

9

10

11

12

$.ajaxTransport( dataType, function( options, originalOptions, jqXHR ) {

send: function( headers, completeCallback ) {

where:

completeCallback has the following signature:

1

function( status, statusText, responses, headers ) {}

where:

Just like prefilters, a transport's factory function can be attached to a specific dataType:

1

2

3

$.ajaxTransport( "script", function( options, originalOptions, jqXHR ) {

The following example shows how a minimal image transport could be implemented:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

$.ajaxTransport( "image", function( s ) {

if ( s.type === "GET" && s.async ) {

send: function( _ , callback ) {

function done( status ) {

var statusText = ( status === 200 ) ? "success" : "error",

image = image.onreadystatechange = image.onerror = image.onload = null;

callback( status, statusText, { image: tmp } );

image.onreadystatechange = image.onload = function() {

image.onerror = function() {

image = image.onreadystatechange = image.onerror = image.onload = null;

Handling Custom Data Types

The jQuery Ajax implementation comes with a set of standard dataTypes, such as text, json, xml, and html.

Use the converters option in $.ajaxSetup() to augment or modify the data type conversion strategies used by $.ajax().

The unminified jQuery source itself includes a list of default converters, which effectively illustrates how they can be used:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

"text json": jQuery.parseJSON,

"text xml": jQuery.parseXML

When you specify a converters option globally in $.ajaxSetup() or per call in $.ajax(), the object will map onto the default converters, overwriting those you specify and leaving the others intact.

For example, the jQuery source uses $.ajaxSetup() to add a converter for "text script":

1

2

3

4

5

6

7

8

9

10

11

script: "text/javascript, application/javascript"

"text script": jQuery.globalEval


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4