【问题标题】:GM_xmlhttpRequest POST request not working cross-domainGM_xmlhttpRequest POST 请求不能跨域工作
【发布时间】: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


    【解决方案1】:

    原来 Tampermonkey 中的“不安全窗口检索”设置只需要设置为 Native。现在好像可以工作了

    【讨论】:

      猜你喜欢
      • 2013-02-24
      • 1970-01-01
      • 2018-07-28
      • 2012-04-15
      • 2011-08-19
      • 2017-02-06
      • 2013-01-10
      • 2015-01-28
      • 1970-01-01
      相关资源
      最近更新 更多