X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax%2Fajax.js;h=cf08676c8ebec0200e61ce6c1966f9579b270d8b;hb=f64eb21fade249bf0dc9d7ab820eafaaf4a521ad;hp=c8e10bd6d7151f48596c6ebbc5cf81d8133f2772;hpb=8a80d05a446ac7ac8a95459fb68932ddf539ff62;p=jquery.git diff --git a/src/ajax/ajax.js b/src/ajax/ajax.js index c8e10bd..cf08676 100644 --- a/src/ajax/ajax.js +++ b/src/ajax/ajax.js @@ -631,40 +631,41 @@ jQuery.extend({ ival = null; } - var status; - try { - status = isTimeout == "timeout" && "timeout" || - !jQuery.httpSuccess( xml ) && "error" || - s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || - "success"; - - // Make sure that the request was successful or notmodified - if ( status != "error" && status != "timeout" ) { - // Cache Last-Modified header, if ifModified mode. - var modRes; - try { - modRes = xml.getResponseHeader("Last-Modified"); - } catch(e) {} // swallow exception thrown by FF if header is not available - - if ( s.ifModified && modRes ) - jQuery.lastModified[s.url] = modRes; - + var status = isTimeout == "timeout" && "timeout" || + !jQuery.httpSuccess( xml ) && "error" || + s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" || + "success"; + + if ( status == "success" ) { + // Watch for, and catch, XML document parse errors + try { // process the data (runs the xml through httpData regardless of callback) var data = jQuery.httpData( xml, s.dataType ); + } catch(e) { + status = "parsererror"; + } + } + + // Make sure that the request was successful or notmodified + if ( status == "success" ) { + // Cache Last-Modified header, if ifModified mode. + var modRes; + try { + modRes = xml.getResponseHeader("Last-Modified"); + } catch(e) {} // swallow exception thrown by FF if header is not available - // If a local callback was specified, fire it and pass it the data - if ( s.success ) - s.success( data, status ); + if ( s.ifModified && modRes ) + jQuery.lastModified[s.url] = modRes; - // Fire the global callback - if( s.global ) - jQuery.event.trigger( "ajaxSuccess", [xml, s] ); - } else - jQuery.handleError(s, xml, status); - } catch(e) { - status = "parsererror"; - jQuery.handleError(s, xml, status, e); - } + // If a local callback was specified, fire it and pass it the data + if ( s.success ) + s.success( data, status ); + + // Fire the global callback + if( s.global ) + jQuery.event.trigger( "ajaxSuccess", [xml, s] ); + } else + jQuery.handleError(s, xml, status); // The request was completed if( s.global ) @@ -765,7 +766,7 @@ jQuery.extend({ // If the type is "script", eval it in global context if ( type == "script" ) - (new Function( data ))(); + jQuery.globalEval( data ); // Get the JavaScript object, if JSON is used. if ( type == "json" ) @@ -794,7 +795,7 @@ jQuery.extend({ // 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 ) ); + s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) ); }); else s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );