[英]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: 我想从Chrome扩展程序向PHP页面发送XHR(使用GET方法)。但是,当我尝试运行代码时,出现错误:
"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. 当我直接在浏览器中调用PHP页面时,它可以很好地加载,因此无法找到该文件不会导致该错误。 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. 由于这些错误,我无法将数据从扩展名发送到PHP页面以存储在数据库中。我在扩展名的manifest.json中(在权限下)包含了https:// * /,但仍然没有工作。
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 the PHP is a HTTP page.Could this be the cause of problem.If yes how to overcome this. PS:运行扩展并发送XHR的页面是HTTPS页面,而PHP是HTTP页面,这可能是问题的原因,如果是,如何解决这个问题。
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). 如果要在Chrome扩展程序中使用XHR请求,请将其放置在扩展程序页面(背景页面)中。
And when you do, make sure you add the the proper match patterns under permission: 然后,请确保在权限下添加正确的匹配模式:
http://code.google.com/chrome/extensions/match_patterns.html 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 . 例如, https://*/
应该是https://*/*
并且您的XHR应该在背景页面中 ,在该页面中您的内容脚本通过Messenger与其通信 。
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. 如果声明了适当的权限,则可以从内容脚本中生成cross-origin-xhr。
You cannot. 你不能。 XHR is subject to the same origin policy . XHR遵循相同的原产地政策 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.