开发者

Accessing 192.168.x.x through AJAX in a Chrome extension

开发者 https://www.devze.com 2023-03-24 07:56 出处:网络
Basically, I have an AJAX request like this: $.ajax({ url:\"http://192.168.0.100/\", success: function(x) { console.log(x); }

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",
    "ta开发者_StackOverflow中文版bs",
    "*.*",
    "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?


Try using "http://192.168.0.100/*" instead of "192.168.0.100/*". The scheme needs to be specified, see Match Patterns for reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消