javascript - XMLHttpRequest prototype of onreadystatechange not called -


i'm trying detect when ajax call finishes in uiwebview. modified code in answer: javascript detect ajax event best of abilities. here attempt:

var s_ajaxlistener = new object(); s_ajaxlistener.temponreadystatechange = xmlhttprequest.prototype.onreadystatechange; s_ajaxlistener.callback = function () {     window.location='ajaxhandler://' + this.url; };  xmlhttprequest.prototype.onreadystatechange = function() {     alert("onreadystatechange called");     s_ajaxlistener.temponreadystatechange.apply(this, arguments);     if(s_ajaxlistener.readystate == 4 && s_ajaxlistener.status == 200) {         s_ajaxlistener.callback();     } } 

i'm injecting webview alert never firing. if place alert @ beginning or end of script, it'll fire i'm there no syntax errors.

i'm not js guy i'm hoping trivial problem.

putting generic onreadystatechange in xmlhttprequest.prototype didn't work me. code linked can adapted invoke custom function whenever event occurs:

var s_ajaxlistener = {}; s_ajaxlistener.tempopen = xmlhttprequest.prototype.open; s_ajaxlistener.tempsend = xmlhttprequest.prototype.send; // callback invoked on readystatechange s_ajaxlistener.callback = function () {     // "this" xhr object     // contain status , readystate     console.log(this); }  xmlhttprequest.prototype.open = function(a,b) {   if (!a) var a='';   if (!b) var b='';   s_ajaxlistener.tempopen.apply(this, arguments);   s_ajaxlistener.method = a;     s_ajaxlistener.url = b;   if (a.tolowercase() == 'get') {     s_ajaxlistener.data = b.split('?');     s_ajaxlistener.data = s_ajaxlistener.data[1];   } }  xmlhttprequest.prototype.send = function(a,b) {   if (!a) var a='';   if (!b) var b='';   s_ajaxlistener.tempsend.apply(this, arguments);   if(s_ajaxlistener.method.tolowercase() == 'post')s_ajaxlistener.data = a;   // assigning callback onreadystatechange   // instead of calling directly   this.onreadystatechange = s_ajaxlistener.callback; } 

http://jsfiddle.net/s6xqu/


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -