简体   繁体   English

将XHR从Chrome扩展程序发送到PHP页面时出错:仅HTTP支持跨源请求

[英]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遵循相同的原产地政策

You could use JSONP instead though. 您可以改用JSONP

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AngularJS错误:仅支持协议方案的跨源请求:http,数据,chrome扩展,https - AngularJS Error: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https 交叉源请求仅支持协议方案:http,数据,chrome,chrome-extension,https - Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https 无法加载“ username:password http://链接:仅协议方案http,数据,chrome,chrome扩展名支持跨源请求 - failed to load "username:password http:// link: Cross origin requests are only supported for protocol schemes http, data, chrome, chrome-extension vs2008中没有错误但在Chrome中错误= XMLHttpRequest无法加载文件:仅支持HTTP的跨源请求 - no error in vs2008 but in Chrome Error= XMLHttpRequest cannot load file: Cross origin requests are only supported for HTTP 跨源请求仅支持HTTP,即使在Chrome --allow-file-access-from-files之后仍未解决 - Cross origin requests are only supported for HTTP not fixed even after Chrome --allow-file-access-from-files 错误:仅对具有D3js的HTTP支持跨源请求 - Error: Cross origin requests are only supported for HTTP with D3js “仅 HTTP 支持跨源请求。” 加载本地文件时出错 - "Cross origin requests are only supported for HTTP." error when loading a local file 从 Chrome 扩展程序执行跨源请求时存在 XMLHTTPRequest 漏洞? - XMLHTTPRequest vulnerabilities when doing cross origin requests from a Chrome extension? 跨域请求仅支持 HTTP,但不支持跨域 - Cross origin requests are only supported for HTTP but it's not cross-domain 仅协议方案支持React Native WebView Cross起源请求:http,data,chrome,https - React Native WebView Cross origin requests are only supported for protocol schemes: http, data, chrome, https
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM