X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=86709005e0a0b7ce720d204acf34c9b140bb4176;hb=eed3803c98bf5c074e40aad12f2e91435bf81154;hp=40524fb47c36458598178f548e48df53808c02f5;hpb=8c9d32723a8943d4595eb5e04be8f891a8ff7a7f;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 40524fb..8670900 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -51,9 +51,9 @@ jQuery.fn.extend({ type = "POST"; } } - + var self = this; - + // Request the remote document jQuery.ajax({ url: url, @@ -107,9 +107,9 @@ jQuery.fn.extend({ null : jQuery.isArray(val) ? jQuery.map( val, function(val, i){ - return {name: elem.name, value: val}; + return {name: elem.name, value: val.replace(/\r?\n/g, "\r\n")}; }) : - {name: elem.name, value: val}; + {name: elem.name, value: val.replace(/\r?\n/g, "\r\n")}; }).get(); } }); @@ -393,9 +393,9 @@ jQuery.extend({ current, prev, checker, + conv, conv1, conv2, - oneConv, convertion, dataTypes = s.dataTypes, converters = s.converters, @@ -419,23 +419,28 @@ jQuery.extend({ if ( prev !== "*" && current !== "*" && prev !== current ) { - oneConv = conv1 = - converters[ ( conversion = prev + " " + current ) ] || + conv = converters[ ( conversion = prev + " " + current ) ] || converters[ "* " + current ]; - if ( oneConv !== true ) { - - if ( ! oneConv && prev !== "text" && current !== "text" ) { - conv1 = converters[ prev + " text" ] || converters[ "* text" ]; - conv2 = converters[ "text " + current ]; - } - - if ( oneConv || conv1 && conv2 ) { - response = oneConv ? conv1( response ) : conv2( conv1( response ) ); - } else { - throw "no " + conversion; + conv1 = conv2 = 0; + + if ( ! conv && prev !== "text" && current !== "text" ) { + conv1 = converters[ prev + " text" ] || converters[ "* text" ]; + conv2 = converters[ "text " + current ]; + if ( conv1 === true ) { + conv = conv2; + } else if ( conv2 === true ) { + conv = conv1; } } + + if ( ! ( conv || conv1 && conv2 ) ) { + throw conversion; + } + + if ( conv !== true ) { + response = conv ? conv( response ) : conv2( conv1( response ) ); + } } } else if ( s.dataFilter ) { @@ -489,9 +494,10 @@ jQuery.extend({ } } - // Attach deferreds - jXHR.success = jXHR.then = deferred.then; - jXHR.error = jXHR.fail = deferred.fail; + // Attach deferreds + deferred.promise( jXHR ); + jXHR.success = jXHR.then; + jXHR.error = jXHR.fail; jXHR.complete = completeDeferred.then; // Remove hash character (#7531: and string promotion) @@ -637,19 +643,19 @@ jQuery.extend({ value = jQuery.isFunction(value) ? value() : value; s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value); }; - + // Set traditional to true for jQuery <= 1.3.2 behavior. if ( traditional === undefined ) { traditional = jQuery.ajaxSettings.traditional; } - + // If an array was passed in, assume that it is an array of form elements. if ( jQuery.isArray(a) || a.jquery ) { // Serialize the form elements jQuery.each( a, function() { add( this.name, this.value ); }); - + } else { // If traditional, encode the "old" way (the way 1.3.2 or older // did it), otherwise encode params recursively. @@ -682,7 +688,7 @@ function buildParams( prefix, obj, traditional, add ) { buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v, traditional, add ); } }); - + } else if ( !traditional && obj != null && typeof obj === "object" ) { // If we see an array here, it is empty and should be treated as an empty // object @@ -695,7 +701,7 @@ function buildParams( prefix, obj, traditional, add ) { buildParams( prefix + "[" + k + "]", v, traditional, add ); }); } - + } else { // Serialize scalar item. add( prefix, obj ); @@ -895,7 +901,7 @@ if ( window.ActiveXObject ) { return new window.XMLHttpRequest(); } catch( xhrError ) {} } - + try { return new window.ActiveXObject("Microsoft.XMLHTTP"); } catch( activeError ) {}