在Chrome扩展程序中通过AJAX访问192.168.xx
基本上,我有一个像这样的 AJAX 请求:
$.ajax({ url: "http://192.168.0.100/",
success: function(x) { console.log(x); }
});
在扩展的 manifest.json
中定义了以下权限数组:
"permissions": [
"notifications",
"tabs",
"*.*",
"192.168.0.100",
"192.168.0.100/*",
]
对 192.168.0.100
的请求失败,并出现以下错误:
XMLHttpRequest cannot load http://192.168.0.100/.
Origin chrome-extension://<hash> is not allowed by Access-Control-Allow-Origin.
我已经做的就是在 index.php
中附加此标头:
Header("Access-Control-Allow-Origin: *");
但没有效果。
如何才能使对本地 IP 的 AJAX 请求在 Chrome 扩展程序中正常工作?
Basically, I have an AJAX request like this:
$.ajax({ url: "http://192.168.0.100/",
success: function(x) { console.log(x); }
});
with the following permissions array defined in manifest.json
of the extension:
"permissions": [
"notifications",
"tabs",
"*.*",
"192.168.0.100",
"192.168.0.100/*",
]
A request to 192.168.0.100
fails with the following error:
XMLHttpRequest cannot load http://192.168.0.100/.
Origin chrome-extension://<hash> is not allowed by Access-Control-Allow-Origin.
What I already did is appending this header in index.php
:
Header("Access-Control-Allow-Origin: *");
but to no avail.
What can I do to make AJAX requests to local IPs work in a Chrome extension?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
"http://192.168.0.100/*"
而不是"192.168.0.100/*"
。需要指定方案,请参阅匹配模式以供参考。Try using
"http://192.168.0.100/*"
instead of"192.168.0.100/*"
. The scheme needs to be specified, see Match Patterns for reference.