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...
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.