X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=cc871330df16fbbc0216182f11f2ed8ee3ec974e;hb=9dc6e0c572b9c809a3a4c123071d96d48a01dd1c;hp=ffd870c284e854aa710a9f7dcf53672209919d4b;hpb=d1931a8241dcac1617cc8388f6dd6284c89c545d;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index ffd870c..cc87133 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,10 +1,13 @@ +(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, + rscript = /)<[^<]*)*<\/script>/gi, + rselectTextarea = /^(?:select|textarea)/i, + rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, + rbracket = /\[\]$/, jsre = /\=\?(&|$)/, rquery = /\?/, - rts = /(\?|&)_=.*?(&|$)/, + rts = /([?&])_=[^&]*(&?)/, rurl = /^(\w+:)?\/\/([^\/?#]+)/, r20 = /%20/g, @@ -59,7 +62,7 @@ jQuery.fn.extend({ // See if a selector was specified self.html( selector ? // Create a dummy div to hold the results - jQuery("
") + jQuery("
") // inject the contents of the document in, removing the scripts // to avoid any 'Permission Denied' errors in IE .append(res.responseText.replace(rscript, "")) @@ -238,23 +241,24 @@ jQuery.extend({ // Handle JSONP-style loading var customJsonp = window[ jsonp ]; + window[ jsonp ] = function( tmp ) { data = tmp; jQuery.ajax.handleSuccess( s, xhr, status, data ); jQuery.ajax.handleComplete( s, xhr, status, data ); if ( jQuery.isFunction( customJsonp ) ) { - customJsonp( tmp ); - } - else { - // Garbage collect - window[ jsonp ] = undefined; - - try { - delete window[ jsonp ]; - } catch( jsonpError ) {} - } - + customJsonp( tmp ); + + } else { + // Garbage collect + window[ jsonp ] = undefined; + + try { + delete window[ jsonp ]; + } catch( jsonpError ) {} + } + if ( head ) { head.removeChild( script ); } @@ -444,8 +448,9 @@ jQuery.extend({ // Fire the complete handlers if ( !jsonp ) { - jQuery.ajax.handleComplete( s, xhr, status, data ); - } + jQuery.ajax.handleComplete( s, xhr, status, data ); + } + if ( isTimeout === "timeout" ) { xhr.abort(); } @@ -482,7 +487,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 ); @@ -538,7 +543,7 @@ function buildParams( prefix, obj, traditional, add ) { if ( jQuery.isArray(obj) ) { // Serialize array item. jQuery.each( obj, function( i, v ) { - if ( traditional || /\[\]$/.test( prefix ) ) { + if ( traditional || rbracket.test( prefix ) ) { // Treat each array item as a scalar. add( prefix, v ); @@ -625,9 +630,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; @@ -646,8 +650,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 ) { @@ -682,5 +685,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 );