javascript - 覆盖发布请求
问题描述
我将这段代码放在控制台中:
XMLHttpRequest.prototype.send = function(body) {
// modifies inputted request
newBody = JSON.parse(body);
newBody.points = 417;
// sends modified request
this.realSend(JSON.stringify(newBody));
}
它应该在每次发送请求时都获得417分,但是当我查看请求正文时,它仍然显示原来的积分数量。有什么帮助吗?
解决方案
尝试将alert()
or添加console.log()
到您的修改XMLHttpRequest.prototype.send
中以检查它是否确实有效。有一种方法可以静默地防止这种修改。
推荐阅读
- python-3.x - 如何在 Scrapy URL 请求中启用 JavaScript?
- opus - Libopus 编码器 max_data_bytes 字段使用什么值?
- scala - 如何将函数传递给 RDD.map?
- ruby - NoMethodError 但做了'require_relative'
- javascript - Chrome 扩展浏览器操作仅有效一次
- google-bigquery - 使用自定义列名将 Avro 文件加载到具有嵌套记录的 GCS
- cluster-analysis - 在 k-means 聚类中,边际距离平方和是否在减少?
- javascript - Odoo 11 添加弹出语法错误:
- python - 在 numpy 二维数组中计算大于的最佳方法
- javascript - 为什么这个错误的 IIFE 函数会返回这个