X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=441a7b9bf67b21d7838a2ac9250726b9be83c329;hb=b8ceedbe2ba07f87a0f0e3862dfe012e8aa863b3;hp=d7237fc3fb13fcfc08dac9c18bff78046cbe5ad2;hpb=11761def421412df7ea4d3414310befef450b7ea;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index d7237fc..441a7b9 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -97,6 +97,7 @@ jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".sp var jsc = now(); jQuery.extend({ + get: function( url, data, callback, type ) { // shift arguments if data argument was ommited if ( jQuery.isFunction( data ) ) { @@ -112,6 +113,13 @@ jQuery.extend({ dataType: type }); }, + + // Create the request object; Microsoft failed to properly + // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available + getAjaxTransport : function() { + return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); + }, + getScript: function( url, callback ) { return jQuery.get(url, null, callback, "script"); @@ -236,12 +244,13 @@ jQuery.extend({ jQuery.event.trigger( "ajaxStart" ); // Matches an absolute URL, and saves the domain - var remote = /^(?:\w+:)?\/\/([^\/?#]+)/; + var parts = /^(\w+:)?\/\/([^\/?#]+)/.exec( s.url ); // If we're requesting a remote document // and trying to load JSON or Script with a GET - if ( s.dataType == "script" && type == "GET" - && remote.test(s.url) && remote.exec(s.url)[1] != location.host ){ + if ( s.dataType == "script" && type == "GET" && parts + && ( parts[1] && parts[1] != location.protocol || parts[2] != location.host )){ + var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.src = s.url; @@ -272,9 +281,8 @@ jQuery.extend({ var requestDone = false; - // Create the request object; Microsoft failed to properly - // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available - var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); + // Create the request object + var xhr = jQuery.getAjaxTransport(); // Open the socket // Passing null username, generates a login popup on Opera (#2865) @@ -336,7 +344,7 @@ jQuery.extend({ // Watch for, and catch, XML document parse errors try { // process the data (runs the xml through httpData regardless of callback) - data = jQuery.httpData( xhr, s.dataType, s.dataFilter ); + data = jQuery.httpData( xhr, s.dataType, s ); } catch(e) { status = "parsererror"; } @@ -460,7 +468,7 @@ jQuery.extend({ return false; }, - httpData: function( xhr, type, filter ) { + httpData: function( xhr, type, s ) { var ct = xhr.getResponseHeader("content-type"), xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0, data = xml ? xhr.responseXML : xhr.responseText; @@ -469,8 +477,9 @@ jQuery.extend({ throw "parsererror"; // Allow a pre-filtering function to sanitize the response - if( filter ) - data = filter( data, type ); + // s != null is checked to keep backwards compatibility + if( s && s.dataFilter ) + data = s.dataFilter( data, type ); // If the type is "script", eval it in global context if ( type == "script" )