X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=686aa552453c8378eef6a5a77b23281467d7854e;hb=c119a80ea37a6940ec55dfb7b9f9b296800c7928;hp=eee3f06f2f4bddff2e10d968a5f8941f6d1ef0e8;hpb=d0eda6827f9bfcf88906e4e45f357cb40e425a05;p=jquery.git diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js index eee3f06..686aa55 100644 --- a/src/ajax/ajax.js +++ b/src/ajax/ajax.js @@ -342,7 +342,6 @@ jQuery.extend({ get: function( url, data, callback, type, ifModified ) { // shift arguments if data argument was ommited if ( data && data.constructor == Function ) { - type = callback; callback = data; data = null; } @@ -466,11 +465,7 @@ jQuery.extend({ * @cat AJAX */ getJSON: function( url, data, callback ) { - if(callback) - jQuery.get(url, data, callback, "json"); - else { - jQuery.get(url, data, "json"); - } + jQuery.get(url, data, callback, "json"); }, /** @@ -597,7 +592,6 @@ jQuery.extend({ * * (String) url - The URL of the page to request. * - * (String) data - A string of data to be sent to the server (POST only). * * (String) dataType - The type of data that you're expecting back from * the server (e.g. "xml", "html", "script", or "json"). @@ -626,6 +620,21 @@ 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 + * string, if not already a string. Is appended to the url for GET-requests. + * Override processData option to prevent processing. + * + * (String) contentType - When sending data to the server, use this content-type, + * default is "application/x-www-form-urlencoded", which is fine for most cases. + * + * (Boolean) processData - By default, data passed in as an object other as string + * will be processed and transformed into a query string, fitting to the default + * content-type "application/x-www-form-urlencoded". If you want to send DOMDocuments, + * set this option to false. + * + * (Boolean) async - By default, all requests are send asynchronous (set to true). + * If you need synchronous requests, set this option to false. + * * @example $.ajax({ * type: "GET", * url: "test.js", @@ -707,15 +716,18 @@ jQuery.extend({ success: null, error: null, dataType: null, - data: null, url: null, + data: null, + contentType: "application/x-www-form-urlencoded", + processData: true, + async: true }, s); // if data available if ( s.data ) { // convert data if not already a string - if (typeof s.data != 'string') - s.data = jQuery.param(s.data) + if (s.processData && typeof s.data != 'string') + s.data = jQuery.param(s.data); // append data to url for get requests if( s.type.toLowerCase() == "get" ) // "?" + data or "&" + data (in case there are already params) @@ -732,11 +744,11 @@ jQuery.extend({ var xml = new XMLHttpRequest(); // Open the socket - xml.open(s.type, s.url, true); + xml.open(s.type, s.url, s.async); // Set the correct header, if data is being sent if ( s.data ) - xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xml.setRequestHeader("Content-Type", s.contentType); // Set the If-Modified-Since header, if ifModified mode. if ( s.ifModified ) @@ -891,8 +903,16 @@ jQuery.extend({ // Otherwise, assume that it's an object of key/value pairs } else { // Serialize the key/values - for ( var j in a ) - s.push( j + "=" + encodeURIComponent( a[j] ) ); + 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] ) ); + } + } } // Return the resulting serialization