javascript - 尝试在 Tampermonkey 中使用 GM_xmlhttpRequest 发布数据
问题描述
我正在尝试将数据从 tampermonkey 脚本发布到我的本地主机服务器。我已经编写了标准的 GM_xmlhttpRequest。我已经编写了所有必需的@grant 和@include。以下是 XHR 代码:
GM_xmlhttpRequest({
method: "POST",
url: "http://localhost:8080/user/index.php",
data: "Hello World!",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0",
"Accept": "text/xml"
},
onload: function(response){
console.log(response.responseText);
},
})
我正在获取 php 中的数据。我面临的问题是,每当我运行脚本并在 chrome 中检查它时,我都会在 doc 下看到我的 php 文件,而不是在网络选项卡中看到 XHR。以下是截图:
以下是我的php代码:
<?php
$rawdata = file_get_contents("php://input");
var_dump($rawdata);
?>
这是我看到的输出
Hello string(0) ""
我不确定我错在哪里。
解决方案
推荐阅读
- svg - 删除 svg 中 rect 内文本元素周围的空间
- python - 如何使用 Celery 使用来自 SQS 的 S3 事件?
- java - 我试图理解递归?为什么当我运行此代码时答案是 13
- python - python unittest 仅在 AWS Lambda 中运行时不运行任何测试(在 0.000 秒内运行 0 次测试)
- stata - Stata 空间面板模型:错误代码 3200
- javascript - 如何将脚本转移到多个谷歌工作表标签
- arrays - 如何在角度 12 中迭代数组?(打字稿火力基地)
- security - 如何使用模拟数据集作为隐马尔可夫模型的观察?
- python-3.x - 在 Jupyter Lab 中关闭时自动清除笔记本输出?
- oracle - 将相关的 oracle 子查询转换为单个查询