【发布时间】:2015-03-05 01:33:09
【问题描述】:
您好,我是 ionic 新手,我正在尝试使用 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 正在工作。 提前致谢
【问题讨论】:
标签: android angularjs ionic-framework