X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=ajax%2Fajax.js;h=8e0f81f5750d00232acab5465d97056a40c2be5a;hb=66bd98be22d50cc09bf14f9aaa0102771a3b990d;hp=f48f74c08c60c03af35083fac7d729d5fa3a374f;hpb=50cdc997b81dcc1994a5f04e44dabf01fd6198de;p=jquery.git diff --git a/ajax/ajax.js b/ajax/ajax.js index f48f74c..8e0f81f 100644 --- a/ajax/ajax.js +++ b/ajax/ajax.js @@ -13,6 +13,15 @@ if ( typeof XMLHttpRequest == 'undefined' && typeof window.ActiveXObject == 'fun $.xmlActive=0; $.xml = function( type, url, data, ret ) { + if ( !url ) { + ret = type.onComplete; + var onSuccess = type.onSuccess; + var onError = type.onError; + data = type.data; + url = type.url; + type = type.type; + } + var xml = new XMLHttpRequest(); if ( xml ) { @@ -24,7 +33,8 @@ $.xml = function( type, url, data, ret ) { // Set header so calling script knows that it's an XMLHttpRequest xml.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); - /* Force "Connection: close" for Mozilla browsers to work around + /* Borrowed from Prototype: + * Force "Connection: close" for Mozilla browsers to work around * a bug where XMLHttpReqeuest sends an incorrect Content-length * header. See Mozilla Bugzilla #246651. */ @@ -53,6 +63,13 @@ $.xml = function( type, url, data, ret ) { $.xmlActive = 0 } + if ( xml.status && xml.status >= 200 && xml.status < 300 ) { + if ( onSuccess ) + onSuccess( xml ); + } else if ( onError ) { + onError( xml ); + } + // Process result if ( ret ) ret(xml); @@ -123,7 +140,7 @@ $.fn.load = function(a,o,f) { $.xml(t,a,o,function(res){ // Assign it and execute all scripts self.html(res.responseText).find("script").each(function(){ - try { $.execute( this.text || this.textContent || this.innerHTML || ""); } catch(e){} + try { eval( this.text || this.textContent || this.innerHTML || ""); } catch(e){} }); // Callback function @@ -316,7 +333,7 @@ $.fn.putForm = function(target, pre_cb, post_cb, url, mth) { $(target).load(url, this.vars, post_cb); } else { this.vars.push({name: 'evaljs', value: 1}); - $.xml(mth, url, $.param(this.vars), function(r) { $.execute(r.responseText); }); + $.xml(mth, url, $.param(this.vars), function(r) { eval(r.responseText); }); } return this;