简体   繁体   English

访问控制允许原点 - 不工作

[英]Access Control Allow Origin - Not Working

I have a PHP API that verifies the specified credentials. 我有一个PHP API来验证指定的凭据。 At the beginning of my PHP file I have this 在我的PHP文件的开头,我有这个

header('Access-Control-Allow-Origin: http://example.org');
header('Access-Control-Max-Age: 3628800');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header('Content-type: application/json');

Although when I use my API (using AJAX) I get this error: 虽然当我使用我的API(使用AJAX)时,我收到此错误:

XMLHttpRequest cannot load http://api.example.com/?params=parameters+go+here. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.org' is therefore not allowed access.

NOTE: I have reason to believe that there is a flaw in the AJAX 注意:我有理由相信AJAX存在缺陷

$.ajax({
    url: 'http://api.example.com/?type=verify&username=' + username + '&password=' + password,
    dataType: 'json',
    success: function( result ) {
        success = result['success'];
        return success;
    }
});

Any help you could provide would be greatly appreciated. 您将提供的任何帮助将不胜感激。

Thanks, CSF 谢谢,CSF

好吧,如果你只是想测试你的代码,然后下载“允许控制允许原产地”扩展链接〜 在这里 ,但如果你想让它每一个浏览器/客户机上没有扩展名的任何要求工作..然后请参考这里 .. 祝好运!

it's easy... if you use Chrome i suggest you that install Allow-Control-Allow-Origin: * Extension... 这很简单......如果您使用Chrome我建议您安装Allow-Control-Allow-Origin: * Extension ...

在此输入图像描述

After Added to chrome, you just need to Enable/Disable cross-origin resource sharing toggle button... 添加到chrome后,您只需启用/禁用cross-origin resource sharing切换按钮...

https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?utm_source=chrome-app-launcher-info-dialog https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?utm_source=chrome-app-launcher-info-dialog

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM