【发布时间】:2016-08-31 18:42:19
【问题描述】:
我正在尝试通过 Ionic 应用程序中的 post 方法向 HTTPS 服务器请求。但每一次,我都失败了。我试过两种方法。一种方法是使用$http,另一种方法是使用$.ajax。但是还是没有找到正确的方法。代码如下。
-使用$http:
$http({
url: "https://beta.test.com/auth/authenticate/",
method: "POST",
data: {
"userName": "vv9@test.com",
"password": "vv9",
"ipAddress": "2d:5d:3s:1s:3w",
"remeberMe": true
},
headers: {
'Content-Type': 'application/json'
}
}).success(function(res) {
$scope.persons = res; // assign $scope.persons here as promise is resolved here
}).error(function(res) {
$scope.status = res;
});
-使用 $.ajax:
$.ajax({
url: "https://beta.test.com/auth/authenticate/",
type: "POST",
data: {
"userName": "vv9@test.com",
"password": "vv9",
"ipAddress": "2d:5d:3s:1s:3w",
"remeberMe": true
},
headers: {
'Content-Type': 'application/json'
}
}).done(function() {
console.log('Stripe loaded');
}).fail(function() {
console.log('Stripe not loaded');
}).always(function() {
console.log('Tried to load Stripe');
});
如何解决这个问题?代码有什么问题?
【问题讨论】:
-
您遇到了什么错误,您的预期响应是什么?
-
错误是 XMLHttpRequest 无法加载
https://beta.test.com/auth/authenticate/。预检响应包含无效的 HTTP 状态代码 404 -
如果您可以访问服务器,那么这就是您的解决方案。stackoverflow.com/a/33820700/5686100
-
谢谢。似乎与服务器端有关。
标签: jquery angularjs ajax ionic-framework