【发布时间】:2014-03-17 17:06:44
【问题描述】:
我正在 Tampermonkey 中运行一个脚本,并尝试使用 GM_xmlhttpRequest 方法跨域发送 POST 请求。但是它对我不起作用。在控制台中,我只是得到正常的跨域错误:
XMLHttpRequest 无法加载 [domain1]。没有“访问控制允许来源” 请求的资源上存在标头。原点 [domain2] 是 因此不允许访问。
据我了解,GM请求方法的重点在于它支持跨域,不像XMLHttpRequest()。所以我不明白为什么这不能正常工作。 以下是我正在做的事情的要点:
// @match https://[domain2]
// @grant GM_xmlhttpRequest
GM_xmlhttpRequest({
method: "POST",
url: "https://[domain1]/exmaple.php",
data: formData,
onload: function(response) {}
console.log(response.responseText);
}
})
也许我遗漏了一些简单的东西或者我有错误的想法
编辑:我想我应该注意,上面的代码嵌套在一个不同的普通 XMLHttpRequest 中,以防会影响它。
【问题讨论】:
标签: javascript google-chrome tampermonkey gm-xmlhttprequest