1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
//cf : http://stackoverflow.com/questions/3596583/javascript-detect-an-ajax-event
var s_ajaxListener = new Object();
alert(s_ajaxListener);//OK
alert(XMLHttpRequest);//OK
s_ajaxListener.tempOpen = (XMLHttpRequest.prototype.open );
s_ajaxListener.tempSend = (XMLHttpRequest.prototype.send );
//alert(s_ajaxListener.tempOpen);//ok
// this.method :the ajax method used
// this.url :the url of the requested script (including query string, if any) (urlencoded)
// this.data :the data sent, if any ex: foo=bar&a=b (urlencoded)
s_ajaxListener.callback = function () {
//myAjaxHandler(this);
$('body').prepend('AJAX: url=' + this.url+' method = '+this.data+'<br />');
}
//OPEN
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];
}
}
//SEND
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();
} |
Partager