以下代码可在浏览器和iPhone 5s上使用,但不能在iOS模拟器中使用。我试图弄清楚它是模拟器还是离子产品。
我已经在Info.plist中设置了NSAppTransportSecurity以便能够使用http
NSAppTransportSecurity
NSAllows任意负载
和代码:
accountRepo.register($scope.login.registryCode)
.success(function(data){
accountRepo.user = data;
$scope.hideLoading();
$state.go("setPin");
})
.error(function(err){
console.log(err);
$scope.hideLoading();
alert("Incorrect registry code");
});
和回购
app.factory('accountRepo', function($http) {
return {
token: {},
register: function(registryCode) {
return $http.post("http://localhost:9501/register",
{"registryCode": registryCode} );
},
发生错误时,err参数为null。我在Xcode的输出中什么也没得到。我应该看看别的地方吗?
最佳答案
有点晚了,但是有人可能会觉得有用。
执行ionic serve
或ionic run -l
时,这是跨源资源共享(CORS)的问题。
您可以通过在ionic.project
中设置代理来解决此问题。
查看本文以了解更多信息:http://blog.ionic.io/handling-cors-issues-in-ionic/
关于ios - ionic $ http.post在模拟器中失败,但可在浏览器和iPhone中使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33561908/