简体   繁体   中英

Access Control Allow Origin - Not Working

I have a PHP API that verifies the specified credentials. At the beginning of my PHP file I have this

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:

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({
    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

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

it's easy... if you use Chrome i suggest you that install Allow-Control-Allow-Origin: * Extension...

在此输入图像描述

After Added to chrome, you just need to Enable/Disable cross-origin resource sharing toggle button...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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