[英]ionic $http.post fails in emulator but works in browser and iPhone
The code below works in browser and on iPhone 5s but not in the iOS emulator. 以下代码可在浏览器和iPhone 5s上使用,但不能在iOS模拟器中使用。 I'm trying to figure out if it's the emulator or something in ionic. 我试图弄清楚它是模拟器还是离子产品。
I have set the NSAppTransportSecurity in the Info.plist to be able to use http 我已经在Info.plist中设置了NSAppTransportSecurity以便能够使用http
NSAppTransportSecurity NSAllowsArbitraryLoads and the code: NSAppTransportSecurity NSAllowsArbitraryLoads和代码:
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");
});
and the repo 和回购
app.factory('accountRepo', function($http) {
return {
token: {},
register: function(registryCode) {
return $http.post("http://localhost:9501/register",
{"registryCode": registryCode} );
},
The err parameter is null when the error occurs. 发生错误时,err参数为null。 I get nothing in the output in Xcode. 我在Xcode的输出中什么也没得到。 Should I look somewhere else? 我应该看看其他地方吗?
A bit late, but someone might find this useful. 有点晚了,但是有人可能会觉得有用。
It's an issue of cross origin resource sharing (CORS), when doing ionic serve
or ionic run -l
. 在进行ionic serve
或ionic run -l
时,这是跨源资源共享(CORS)的问题。
You can solve that by setting a proxy in your ionic.project
. 您可以通过在ionic.project
设置代理来解决此ionic.project
。
Check this article for more: http://blog.ionic.io/handling-cors-issues-in-ionic/ 检查本文以了解更多信息: http : //blog.ionic.io/handling-cors-issues-in-ionic/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.