X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=d56ae0f1ed0d611d032e3d15604b8c70b88c2490;hb=94e59e287a9fde9425cd96713e8130aef06bc431;hp=652bd2d7153b22a3002b95e68731ce151474bb7c;hpb=953bf593a6233d9f480ee3f706d21950590f40ef;p=jquery.git diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js index 652bd2d..d56ae0f 100644 --- a/src/ajax/ajax.js +++ b/src/ajax/ajax.js @@ -124,12 +124,7 @@ jQuery.fn.extend({ // for some weird reason, it doesn't work if the callback is ommited jQuery.getScript( this.src ); else { - // TODO extract into $.eval - var data = this.text || this.textContent || this.innerHTML || ""; - if (window.execScript) - window.execScript( data ); - else - window.setTimeout( data, 0 ); + jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" ); } }).end(); } @@ -309,6 +304,10 @@ jQuery.extend({ * Loads, and executes, a remote JavaScript file using an HTTP GET request. * All of the arguments to the method (except URL) are optional. * + * Warning: Safari <= 2.0.x is unable to evalulate scripts in a global + * context sychronously. If you load functions via getScript, make sure + * to call them after a delay. + * * @example $.getScript("test.js") * * @example $.getScript("test.js", function(){ @@ -473,7 +472,7 @@ jQuery.extend({ * function gets passed two arguments: The XMLHttpRequest object and a * string describing the type the success of the request. * - * (String) data - Data to be sent to the server. Converted to a query + * (Object|String) data - Data to be sent to the server. Converted to a query * string, if not already a string. Is appended to the url for GET-requests. * Override processData option to prevent processing. * @@ -688,12 +687,8 @@ jQuery.extend({ data = type == "xml" || data ? r.responseXML : r.responseText; // If the type is "script", eval it in global context - // TODO extract as $.eval if ( type == "script" ) { - if (window.execScript) - window.execScript( data ); - else - window.setTimeout( data, 0 ); + jQuery.globalEval( data ); } // Get the JavaScript object, if JSON is used. @@ -721,10 +716,10 @@ jQuery.extend({ } else { // Serialize the key/values for ( var j in a ) { - //if one value is array then treat each array value in part - if (typeof a[j] == 'object') { + // If the value is an array then the key names need to be repeated + if( a[j].constructor == Array ) { for (var k = 0; k < a[j].length; k++) { - s.push( j + "[]=" + encodeURIComponent( a[j][k] ) ); + s.push( j + "=" + encodeURIComponent( a[j][k] ) ); } } else { s.push( j + "=" + encodeURIComponent( a[j] ) ); @@ -734,6 +729,18 @@ jQuery.extend({ // Return the resulting serialization return s.join("&"); + }, + + // evalulates a script in global context + // not reliable for safari + globalEval: function(data) { + if (window.execScript) + window.execScript( data ); + else if(jQuery.browser.safari) + // safari doesn't provide a synchronous global eval + window.setTimeout( data, 0 ); + else + eval.call( window, data ); } });