X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=bfae7824478b2090dcf5bfc3065519379e498c8d;hb=9ad7c21e701f827e108de038ff704f1e9b7022da;hp=f797e1a78698ef48eca2b15fd87de4c676bc8a54;hpb=86ace44fbbdfe90d231877d6d3bb3b85a81782b4;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index f797e1a..bfae782 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,4 +1,6 @@ -var jsc = now(), +(function( jQuery ) { + +var jsc = jQuery.now(), rscript = //gi, rselectTextarea = /select|textarea/i, rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i, @@ -237,17 +239,25 @@ jQuery.extend({ s.dataType = "script"; // Handle JSONP-style loading - window[ jsonp ] = window[ jsonp ] || function( tmp ) { + var customJsonp = window[ jsonp ]; + + window[ jsonp ] = function( tmp ) { data = tmp; jQuery.ajax.handleSuccess( s, xhr, status, data ); jQuery.ajax.handleComplete( s, xhr, status, data ); - // Garbage collect - window[ jsonp ] = undefined; + + if ( jQuery.isFunction( customJsonp ) ) { + customJsonp( tmp ); - try { - delete window[ jsonp ]; - } catch( jsonpError ) {} + } else { + // Garbage collect + window[ jsonp ] = undefined; + try { + delete window[ jsonp ]; + } catch( jsonpError ) {} + } + if ( head ) { head.removeChild( script ); } @@ -259,7 +269,7 @@ jQuery.extend({ } if ( s.cache === false && type === "GET" ) { - var ts = now(); + var ts = jQuery.now(); // try replacing _= if it is there var ret = s.url.replace(rts, "$1_=" + ts + "$2"); @@ -436,7 +446,9 @@ jQuery.extend({ } // Fire the complete handlers - jQuery.ajax.handleComplete( s, xhr, status, data ); + if ( !jsonp ) { + jQuery.ajax.handleComplete( s, xhr, status, data ); + } if ( isTimeout === "timeout" ) { xhr.abort(); @@ -474,7 +486,7 @@ jQuery.extend({ // Send the data try { - xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null ); + xhr.send( (type !== "GET" && s.data) || null ); } catch( sendError ) { jQuery.ajax.handleError( s, xhr, null, e ); @@ -617,9 +629,8 @@ jQuery.extend( jQuery.ajax, { try { // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 return !xhr.status && location.protocol === "file:" || - // Opera returns 0 when status is 304 - ( xhr.status >= 200 && xhr.status < 300 ) || - xhr.status === 304 || xhr.status === 1223 || xhr.status === 0; + xhr.status >= 200 && xhr.status < 300 || + xhr.status === 304 || xhr.status === 1223; } catch(e) {} return false; @@ -638,8 +649,7 @@ jQuery.extend( jQuery.ajax, { jQuery.ajax.etag[url] = etag; } - // Opera returns 0 when status is 304 - return xhr.status === 304 || xhr.status === 0; + return xhr.status === 304; }, httpData: function( xhr, type, s ) { @@ -674,5 +684,10 @@ jQuery.extend( jQuery.ajax, { }); +// Does this browser support XHR requests? +jQuery.support.ajax = !!jQuery.ajaxSettings.xhr(); + // For backwards compatibility jQuery.extend( jQuery.ajax ); + +})( jQuery );