【发布时间】:2018-01-06 04:33:20
【问题描述】:
这是我的 .htaccess 文件。
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
# Cross domain access
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type, authorization"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
Header add Access-Control-Request-Origin "*"
Header add Access-Control-Request-Headers "origin, x-requested-with, content-type, authorization"
Header add Access-Control-Request-Methods "PUT, GET, POST, DELETE, OPTIONS"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
但是当我尝试执行 PUT 请求时,它给了我这样的错误。
:63342/web-wokoshop-partner/index.html?_ijt=vgfnsnd7c4g6l47qh3kt00i8c8#!/suppliers:1 XMLHttpRequest 无法加载 http://abcd.com/SupplierApi/v1/supplier/5。 预检响应包含无效的 HTTP 状态代码 404
这就是我向 angular 提出请求的方式
function updateSupplier(supplier, id) {
var data = {
name: supplier.name,
mobile: supplier.mobile
};
var req = {
method : 'PUT',
url : REST_SERVICE_URI2 + '/' + supplier.id,
data : JSON.stringify(data),
headers : {
'Content-Type' : 'application/json'
}
};
$http(req).then(
function(response) {
alert('supplier updated.');
console.log(data);
},
function(data) {
consile.log(data);
alert('update supplier error.');
alert(data.statusText);
});
}
有什么问题?我错过了什么吗?
【问题讨论】:
-
尝试捕捉你的错误并通过添加
.catch((error) => { console.log(error.response) })记录它
标签: javascript angularjs .htaccess cors