gpt4 book ai didi

javascript - 访问控制允许来源 - 不工作

转载 作者:行者123 更新时间:2023-12-01 14:17:41 25 4
gpt4 key购买 nike

我有一个 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;
}
});

如果您能提供任何帮助,我们将不胜感激。

谢谢,脑脊液

最佳答案

好吧,如果您只是想测试您的代码,请下载“Allow-Control-Allow-Origin”扩展链接 ~ here但是如果你想让它在每个浏览器/客户端上工作而不需要任何扩展.. 那么请引用 here ..祝你好运!

关于javascript - 访问控制允许来源 - 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43534361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com