开发者

Error when sending XHR from Chrome Extension to a PHP page: Cross origin requests are only supported for HTTP

I want to send an XHR (using GET method) from a Chrome Extension to a PHP page.But when I try to run the code, I get an error:

    "Cross origin requests are only supported for HTTP"
    "XMLHttpRequest Exception 101"

The PHP page loads fine when I call it directly in the browser, so being unable to locate the file would not cause the error. Due to these errors I am unable to send data from the extension to the PHP page to store in the database.I have included https://*/ in the manifest.json (under permissions ) of the extension, but it still does not work.

Please let me know how to overcome this error and send the request successfully.

PS: The page on which the extension is running and sending the XHR is a HTTPS page, while 开发者_如何学Gothe PHP is a HTTP page.Could this be the cause of problem.If yes how to overcome this.


I assume your doing this in a Content-Script, if so, then you cannot. It will be treated to the same origin policy. If you want to use XHR requests in a Chrome Extension, place it in your extension pages (Background page).

And when you do, make sure you add the the proper match patterns under permission:

http://code.google.com/chrome/extensions/match_patterns.html

For example, https://*/ should be https://*/* and your XHR should be in a background page where your content script communicates with it through messaging.


I know its a bit old but just in case someone comes across this page. This is a replica of this question.

You can make cross-origin-xhr from your content scripts if you have proper permissions declared.


You cannot. XHR is subject to the same origin policy.

You could use JSONP instead though.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜