Overriding XMLHttpRequest#39;s send method(覆盖 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 的发送方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:覆盖 XMLHttpRequest 的发送方法


基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01