[英]Http Put method not working in AngularJS with headers
我试图在http angularJS中使用put方法,但出现错误
错误:XMLHttpRequest无法加载[url]。 飞行前的响应具有无效的HTTP状态代码404
我的代码是:
var newRentalUrl = serverURL;
var dataObj = JSON.stringify(JSONDATA);
$http.put(newRentalUrl, dataObj, {
headers: {
'Content-Type': 'application/json; charset=UTF-8'
},
}).success(function(responseData) {
try {
$ionicLoading.hide();
console.log(responseData);
//$state.go('payment');
} catch (err) {
console.log(err);
$ionicLoading.hide();
}
$ionicLoading.hide();
}).error(function(data, status, headers, config) {
$ionicLoading.hide();
console.log(data);
});
在服务器端,该方法作为选项接收
2015-10-21T05:37:02.947517 + 00:00 heroku [router]:at = info method = OPTIONS path =“ / v1 / home / xx” host = xxxxxx.herokuapp.com request_id = xxxxx-498d-4026-a39a -xxxxxxx fwd =“ xxx.xxxx.xxx.xxx” dyno = web.1 connect = 0ms服务= 2ms状态= 404字节= 481
将Content-Type更改为“ Content-Type”:'application / x-www-form-urlencoded; charset = UTF-8'
并且,如果这是跨域资源请求,则需要在服务器中添加设置的CORS标头(Access-Control-Allow-Origin)。
希望它可能会起作用。
var newRentalUrl = serverURL;
var dataObj = JSON.stringify(JSONDATA);
$http.put(newRentalUrl, dataObj, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
}).success(function(responseData) {
try {
$ionicLoading.hide();
console.log(responseData);
//$state.go('payment');
} catch (err) {
console.log(err);
$ionicLoading.hide();
}
$ionicLoading.hide();
}).error(function(data, status, headers, config) {
$ionicLoading.hide();
console.log(data);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.