Monitorar qualquer evento ajax
Alguém pode me ajudar a criar um script que verifica as chamadas ajax de qualquer framework como JQuery?
Estou tentando monitorar as chamadas javascript para que eu identifique a chamada em um certo elemento, e assim chame uma função.
Estou pesquisando na internet, mas eu não sei o que pode estar de errado. Segue um exemplo que tentei usar:
var s_ajaxListener = new Object();
// Added for IE support
if(typeof XMLHttpRequest === "undefined") {
XMLHttpRequest = function () {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {}
throw new Error("This browser does not support XMLHttpRequest.");
};
}
s_ajaxListener.tempOpen = XMLHttpRequest.prototype.open;
s_ajaxListener.tempSend = XMLHttpRequest.prototype.send;
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;
s_ajaxListener.callback();
}
s_ajaxListener.callback = function () {
//Aqui é a chamada
}Discussão (6)
Carregando comentários...