【问题标题】:ionic $http.post fails in emulator but works in browser and iPhoneionic $http.post 在模拟器中失败,但在浏览器和 iPhone 中有效
【发布时间】:2016-02-07 07:28:59
【问题描述】:

以下代码适用于浏览器和 iPhone 5s,但不适用于 iOS 模拟器。我试图弄清楚它是模拟器还是离子中的东西。

我已经在 Info.plist 中设置了 NSAppTransportSecurity 以便能够使用 http

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");
});

和回购

app.factory('accountRepo', function($http) {
   return {
     token: {},
     register: function(registryCode) {
       return $http.post("http://localhost:9501/register",
       {"registryCode": registryCode} );
     },

发生错误时,err 参数为空。我在 Xcode 的输出中一无所获。我应该看看别的地方吗?

【问题讨论】:

    标签: ios angularjs cordova ionic


    【解决方案1】:

    有点晚了,但有人可能会觉得这很有用。

    在执行ionic serveionic run -l 时,这是一个跨源资源共享 (CORS) 问题。

    您可以通过在 ionic.project 中设置代理来解决这个问题。

    查看这篇文章了解更多信息:http://blog.ionic.io/handling-cors-issues-in-ionic/

    【讨论】:

      猜你喜欢
      • 2019-05-23
      • 2015-05-04
      • 2021-05-25
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2015-08-25
      • 2015-09-07
      相关资源
      最近更新 更多