contentScript 具有 $.ajax() 的 CORS 问题
contentScript having CORS issue with $.ajax()
我收到此错误,希望 $.ajax()
在我的 contentScript
中工作
XMLHttpRequest cannot load http://example.com/tab/index.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'chrome-extension://gncbffieahbpgabchdjmhipkmahk****' is therefore not allowed access.
这就是 ajax 在我的 contentscript.js
中的样子
$.ajax({type: "GET",url: "http://example.com/tab/index.php", success: function(data){
alert(data);
}});
并且在我的 http://example.com/tab/index.html 中我已经声明
header('Access-Control-Allow-Origin: *');
知道为什么它仍然不起作用吗?
这肯定不是扩展方面的问题。它清楚地表明响应不包含所需的 header。您可以在 Dev Tools 的网络选项卡中确认。
查看您的 server-side 代码,但这个问题无法回答。
当然,除非您愿意将您的站点添加到权限中。那么 CORS headers 就不再重要了。
服务器似乎不允许跨域请求...
试试 JSONP (there's an example here)
我收到此错误,希望 $.ajax()
在我的 contentScript
XMLHttpRequest cannot load http://example.com/tab/index.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'chrome-extension://gncbffieahbpgabchdjmhipkmahk****' is therefore not allowed access.
这就是 ajax 在我的 contentscript.js
中的样子$.ajax({type: "GET",url: "http://example.com/tab/index.php", success: function(data){
alert(data);
}});
并且在我的 http://example.com/tab/index.html 中我已经声明
header('Access-Control-Allow-Origin: *');
知道为什么它仍然不起作用吗?
这肯定不是扩展方面的问题。它清楚地表明响应不包含所需的 header。您可以在 Dev Tools 的网络选项卡中确认。
查看您的 server-side 代码,但这个问题无法回答。
当然,除非您愿意将您的站点添加到权限中。那么 CORS headers 就不再重要了。
服务器似乎不允许跨域请求... 试试 JSONP (there's an example here)