Friday, May 17, 2024
184
rated 0 times [  187] [ 3]  / answers: 1 / hits: 17063  / 12 Years ago, wed, march 14, 2012, 12:00:00

I'm trying to log (and later modify) the data XMLHttpRequest sends to a server by overriding XMLHttpRequest.send function.



My function logs the data correctly to the console, however the request doesn't finish, therefore the browser keeps waiting for the response indefinitely.



Any ideas what's wrong with the code?



XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
var newSend = function(vData) { console.log(data: + vData); realSend(vData); };
XMLHttpRequest.prototype.send = newSend;

More From » xmlhttprequest

 Answers
17
XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
// here this points to the XMLHttpRequest Object.
var newSend = function(vData) { console.log(data: + vData); this.realSend(vData); };
XMLHttpRequest.prototype.send = newSend;

[#86854] Tuesday, March 13, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quentinaveryb

Total Points: 102
Total Questions: 100
Total Answers: 93

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
quentinaveryb questions
Thu, Aug 6, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;