X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=d72ddc6b7351b4323c5864b5711f7b2069074775;hb=42f30dd1812fc0ee262eaa43f0a354d8e439938c;hp=51f9d609f720984b533625424456b1baa223400b;hpb=fea94528e2cad2d94e4e642273a5a98eb98c1729;p=jquery.git
diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js
index 51f9d60..d72ddc6 100644
--- a/src/ajax/ajax.js
+++ b/src/ajax/ajax.js
@@ -4,16 +4,16 @@ jQuery.fn.extend({
* Load HTML from a remote file and inject it into the DOM, only if it's
* been modified by the server.
*
- * @example $("#feeds").loadIfModified("feeds.html")
+ * @example $("#feeds").loadIfModified("feeds.html");
* @before
").html(data).evalScripts();
+ if ( type == "html" )
+ jQuery("
").html(data).evalScripts();
return data;
},
// Serialize an array of form elements or a set of
// key/values into a query string
- param: function(a) {
+ param: function( a ) {
var s = [];
// If an array was passed in, assume that it is an array
// of form elements
- if ( a.constructor == Array || a.jquery ) {
+ if ( a.constructor == Array || a.jquery )
// Serialize the form elements
- for ( var i = 0; i < a.length; i++ )
- s.push( a[i].name + "=" + encodeURIComponent( a[i].value ) );
+ jQuery.each( a, function(){
+ s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
+ });
// Otherwise, assume that it's an object of key/value pairs
- } else {
+ 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') {
- for (var k = 0; k < a[j].length; k++) {
- s.push( j + "[]=" + encodeURIComponent( a[j][k] ) );
- }
- } else {
- s.push( j + "=" + encodeURIComponent( a[j] ) );
- }
- }
- }
+ for ( var j in a )
+ // If the value is an array then the key names need to be repeated
+ if ( a[j] && a[j].constructor == Array )
+ jQuery.each( a[j], function(){
+ s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
+ });
+ else
+ s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
// Return the resulting serialization
return s.join("&");
},
- // TODO document me
- eval: function(data) {
- if (window.execScript)
- window.execScript( data );
- else
- eval.call( window, data );
+ // evalulates a script in global context
+ // not reliable for safari
+ globalEval: function( data ) {
+ data = jQuery.trim( data );
+ if ( 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 );
+ }
}
});