-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathajaxListener.js
More file actions
45 lines (38 loc) · 1.33 KB
/
ajaxListener.js
File metadata and controls
45 lines (38 loc) · 1.33 KB
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
// This code is forked from: https://gist.github.com/icodejs/3183154
var open = window.XMLHttpRequest.prototype.open,
send = window.XMLHttpRequest.prototype.send,
onReadyStateChange;
function openReplacement(method, url, async, user, password) {
var syncMode = async !== false ? 'async' : 'sync';
this.syncMode = syncMode;
this.method = method;
this.url = url;
return open.apply(this, arguments);
}
function sendReplacement(data) {
if(this.onreadystatechange) {
this._onreadystatechange = this.onreadystatechange;
}
this.onreadystatechange = onReadyStateChangeReplacement;
this.requestData = data;
return send.apply(this, arguments);
}
function onReadyStateChangeReplacement() {
warnJson = {
"type": "response",
"syncMode": this.syncMode,
"method": this.method,
"url": this.url,
"requestData": this.requestData,
"readyState": this.readyState,
"responseText": this.responseText,
"responseCode": this.status,
"responseHeader": this.getAllResponseHeaders()
};
console.warn(JSON.stringify(warnJson));
if(this._onreadystatechange) {
return this._onreadystatechange.apply(this, arguments);
}
}
window.XMLHttpRequest.prototype.open = openReplacement;
window.XMLHttpRequest.prototype.send = sendReplacement;