简体   繁体   English

Chrome扩展程序-Access-Control-Allow-Origin不允许使用

[英]Chrome Extension - Not allowed by Access-Control-Allow-Origin

I am trying to create a Google Chrome extension, but when I submit my form, I get the following error: 我正在尝试创建Google Chrome扩展程序,但是在提交表单时出现以下错误:

XMLHttpRequest cannot load http://www.domain.com/?i=ajax No "Access-Control-Allow-Origin".

I have checked in the extension list under "Permissions", and I see my website listed there. 我已经在“权限”下签入了扩展名列表,并且看到了我的网站。

This is my manifest.json : 这是我的manifest.json

{
    "name": "My Extension",
    "version": "0.0.1",
    "manifest_version": 2,
    "browser_action": {
        "default_icon": {
            "19": "icons/19x19.png",
            "38": "icons/38x38.png"
        },
        "default_title": "Quick Dashboard",
        "default_popup": "popup.html"
    },
    "permissions": [
       "http://www.domain.com/"
     ]
}

This is the popup.html : 这是popup.html

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery.js"></script> 
<script src="main.js"></script>
    <form id="url" method="post">
    <label for="url">A bar</label>
    <input id="urlname" name="url" type="text" value="" />
    <input type="submit" value="Send" />
    </form> 
    <div id="result"></div>


</div>
</body>
</html>

The ajax.php file: ajax.php文件:

if($_POST){

    die("success");

}

The actual problem with your code was incorrect host permission. 您的代码的实际问题是不正确的主机权限。

It should be (note the asterisk): 应该是(请注意星号):

"permissions": [
   "http://www.domain.com/*"
 ]

That said, Jay S.'s answer works too. 也就是说,Jay S.的答案也适用。

In ajax.php, add 在ajax.php中,添加

header("Access-Control-Allow-Origin : *")

To the top. 到顶部。

暂无
暂无

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

相关问题 Chrome 扩展上的访问控制允许来源 - Access-Control-Allow-Origin on chrome extension Access-Control-Allow-Origin不允许使用Chrome Origin null - Chrome Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin 不允许 XMLHttpRequest - XMLHttpRequest is not allowed by Access-Control-Allow-Origin php原点是Access-Control-Allow-Origin所不允许的 - php Origin is not allowed by Access-Control-Allow-Origin qooxdoo:Access-Control-Allow-Origin不允许XMLHttpRequest Origin null - qooxdoo : XMLHttpRequest Origin null is not allowed by Access-Control-Allow-Origin 请求标头字段不允许Access-Control-Allow-Origin - Request header field Access-Control-Allow-Origin is not allowed Phonegap请求的资源上没有“Access-Control-Allow-Origin”标头。 因此不允许原点&#39;null&#39;访问 - Phonegap No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access Apposver中的“测试失败:错误:Access-Control-Allow-Origin不允许原点”-Appgyver - “Test failed: Error: Origin is not allowed by Access-Control-Allow-Origin” in Composer - Appgyver XMLHttpRequest 无法加载。 Access-Control-Allow-Origin 不允许 Origin http://localhost:63342 - XMLHttpRequest cannot load . Origin http://localhost:63342 is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许AngularJS Origin http:// localhost:8080 - AngularJS Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM