0
我想做一個$ http.post,但這個迴應給我這個錯誤。
XMLHttpRequest無法加載http://XXXXXXXXX:2222/server/api/v1/controllers。預檢響應具有無效的HTTP狀態碼403
所有我讀了互聯網最高審計機關,它的一個故障由CORS,我嘗試沒有成功解決這個問題。
這是我的$ http.post方法。
// Set the Content-Type
$http.defaults.headers.post["Content-Type"] = "application/json";
// Delete the Requested With Header
delete $http.defaults.headers.common['X-Requested-With'];
var config = {
method: 'POST',
headers: {'Content-Type': 'application/json; charset=utf-8'}
}
$http.post("http://XXXXXXXXX:2222/server/api/v1/controllers", objToSave , config)
.then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
console.log(response)
}, function errorCallback(error) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log(error)
});
我正在使用Angular v1.5.5。
希望你能幫幫我,
問候!
CORS錯誤=>檢查CORS設定你的** **的服務器端 – Weedoze
這是否幫助:http://stackoverflow.com/a/38333662/1225328? – sp00m