我有一個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
清楚你的頭是不是** **發送 - 驗證在瀏覽器** **開發工具網絡選項卡,看看有什麼響應頭實際發送 –
@JaromandaX謝謝。剛剛檢查了開發者網絡選項卡,但我不知道如何查看標題。 – csf30816
通過點擊請求(因爲我甚至不知道你有哪個瀏覽器,這是我能建議的最好的) –