我有一个验证指定凭据的PHP API。在我的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');
虽然当我使用我的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.
注意:我有理由相信AJAX存在缺陷
$.ajax({
url: 'http://api.example.com/?type=verify&username=' + username + '&password=' + password,
dataType: 'json',
success: function( result ) {
success = result['success'];
return success;
}
});
非常感谢您提供的任何帮助。
谢谢, CSF