該賞金過期2天。此問題的答案有資格獲得 100聲望獎勵。 現象正在從信譽良好的來源尋找答案。
我有這個代碼放在我的控制臺中:
XMLHttpRequest.prototype.send = function(body) {
// modifies inputted request
newBody = JSON.parse(body);
newBody.points = 417;
// sends modified request
this.realSend(JSON.stringify(newBody));
}
它應該在每次發送請求時使點數為 417,但是當我查看請求正文時,它仍然顯示原始點數。有什么幫助嗎?
uj5u.com熱心網友回復:
嘗試在您的修改中添加alert()或以檢查它是否確實有效。有一種方法可以悄悄地防止這種修改。console.log()XMLHttpRequest.prototype.send
uj5u.com熱心網友回復:
正如其他人所指出的,如果不了解您是如何創建this.realSend.
但是,此代碼將起作用:
const send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function (body) {
const newBody = JSON.parse(body);
newBody.points = 417;
send.call(this, JSON.stringify(newBody));
};
請注意,我沒有將原始send方法存盤在上XMLHttpRequest.prototype,而是保存在一個單獨的變數中,并this通過使用正確的值簡單地呼叫它send.call()。這似乎是一個更清晰的實作,與其他代碼發生沖突的可能性更小。
有關作業示例,請參閱此代碼和框。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/332830.html
標籤:javascript http xmlhttp请求 http-post
