本文介紹了覆蓋 XMLHttpRequest 的發(fā)送方法的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問題描述
我正在嘗試通過重寫 XMLHttpRequest.send
函數(shù)記錄(并稍后修改)XMLHttpRequest
發(fā)送到服務(wù)器的數(shù)據(jù).
I'm trying to log (and later modify) the data XMLHttpRequest
sends to a server by overriding XMLHttpRequest.send
function.
我的函數(shù)將數(shù)據(jù)正確記錄到控制臺(tái),但是請(qǐng)求沒有完成,因此瀏覽器會(huì)無(wú)限期地等待響應(yīng).
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;
這篇關(guān)于覆蓋 XMLHttpRequest 的發(fā)送方法的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!