Subversion-Projekte lars-tiefland.faltradxxs.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
// Ajax mode: abort
2
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
3
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
4
 
5
var pendingRequests = {},
6
	ajax;
7
 
8
// Use a prefilter if available (1.5+)
9
if ( $.ajaxPrefilter ) {
10
	$.ajaxPrefilter( function( settings, _, xhr ) {
11
		var port = settings.port;
12
		if ( settings.mode === "abort" ) {
13
			if ( pendingRequests[ port ] ) {
14
				pendingRequests[ port ].abort();
15
			}
16
			pendingRequests[ port ] = xhr;
17
		}
18
	} );
19
} else {
20
 
21
	// Proxy ajax
22
	ajax = $.ajax;
23
	$.ajax = function( settings ) {
24
		var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
25
			port = ( "port" in settings ? settings : $.ajaxSettings ).port;
26
		if ( mode === "abort" ) {
27
			if ( pendingRequests[ port ] ) {
28
				pendingRequests[ port ].abort();
29
			}
30
			pendingRequests[ port ] = ajax.apply( this, arguments );
31
			return pendingRequests[ port ];
32
		}
33
		return ajax.apply( this, arguments );
34
	};
35
}