您好我是离子新手我正在尝试使用https发送put请求进行更新。在控制器中,我写的是这样的。我指的是https://docs.angularjs.org/api/ng/service/ $ http#put
$scope.update = function(user){
if($localStorage.hasOwnProperty("accessToken") === true) {
var requestContent = $.param({
facebook_url: user.facebook_url,
twitter_username: user.twitter_username
});
var req = {
method: 'PUT',
url: link+'user/profile?id='+$localStorage.accessToken,
data: requestContent,
headers: {'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': 'application/json'}
}
$http(req).success(function(data) {
console.log(data.message);
console.log(data.user)
$ionicLoading.hide();
}).error(function(data) {
console.log(data.message);
$ionicLoading.hide();
});
} else {
console.log($localStorage.accessToken);
console.log(data.message);
$ionicLoading.hide();
}
};
我收到错误XMLHttpRequest cannot load http://192.168.1.7/api/v1/user/profile?id=ccdec73ce10117159a6ba8bc54e4943a6e8cac81. Invalid HTTP status code 405
Request Method:OPTIONS
的.htaccess
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
如果我在.htaccess中有以上这些行,那么post和get工作但是其他选项不起作用。 提前致谢
答案 0 :(得分:0)
对我而言,这听起来像是一个CORS问题。请参阅this answer,其中提供了有关CORS预检请求和Apache配置的更多详细信息。
此外,您是否有理由使用$ http代替$resource?
希望有所帮助