本文介紹了覆蓋 XMLHttpRequest 的發送方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試通過重寫 XMLHttpRequest.send
函數記錄(并稍后修改)XMLHttpRequest
發送到服務器的數據.
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;
推薦答案
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;
這篇關于覆蓋 XMLHttpRequest 的發送方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!