jquery ajax: support for dynamic data arguments, see #2806; added test/data/echoQuery...
[jquery.git] / src / ajax.js
index 3e72488..b90ca16 100644 (file)
@@ -91,7 +91,7 @@ jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".sp
        };
 });
 
-var jsc = (new Date).getTime();
+var jsc = now();
 
 jQuery.extend({
        get: function( url, data, callback, type ) {
@@ -211,7 +211,7 @@ jQuery.extend({
                        s.cache = false;
 
                if ( s.cache === false && s.type.toLowerCase() == "get" ) {
-                       var ts = (new Date()).getTime();
+                       var ts = now();
                        // try replacing _= if it is there
                        var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
                        // if nothing was replaced, add timestamp to the end
@@ -291,9 +291,14 @@ jQuery.extend({
                } catch(e){}
 
                // Allow custom headers/mimetypes
-               if ( s.beforeSend )
-                       s.beforeSend(xml);
-                       
+               if ( s.beforeSend && s.beforeSend(xml, s) === false ) {
+                       // cleanup active request counter
+                       s.global && jQuery.active--;
+                       // close opended socket
+                       xml.abort();
+                       return false;
+               }
+               
                if ( s.global )
                        jQuery.event.trigger("ajaxSend", [xml, s]);
 
@@ -443,9 +448,9 @@ jQuery.extend({
        },
 
        httpData: function( r, type ) {
-               var ct = r.getResponseHeader("content-type");
-               var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0;
-               var data = xml ? r.responseXML : r.responseText;
+               var ct = r.getResponseHeader("content-type"),
+                       xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0,
+                       data = xml ? r.responseXML : r.responseText;
 
                if ( xml && data.documentElement.tagName == "parsererror" )
                        throw "parsererror";
@@ -484,7 +489,7 @@ jQuery.extend({
                                                s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
                                        });
                                else
-                                       s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
+                                       s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) );
 
                // Return the resulting serialization
                return s.join("&").replace(/%20/g, "+");