2014-02-18 171 views
0

我正在Tampermonkey中运行一个脚本,并且我试图使用GM_xmlhttpRequest方法来发送POST请求跨域。但它不适合我。在控制台我只是得到正常的跨域错误:GM_xmlhttpRequest POST请求不能跨域使用

XMLHttpRequest cannot load [domain1]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin [domain2] is therefore not allowed access.

这是我的理解是,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,如果这会影响它。

回答

1

原来Tampermonkey中的“Unsafe window retrieval”设置只需要设置为Native。似乎现在正在工作