离子/角度获得vs后 - 后有时返回0

时间:2016-06-02 10:45:20

标签: angularjs http ionic-framework

我正在使用PHP REST API构建一个Ionic应用程序(Slim 3)

我只使用POST请求。我在iOS设备上运行时遇到HTTP错误:

   2016-06-02 12:34:01.143 connect-app[1987:1343510] {
  "data": null,
  "status": -1,
  "config": {
    "method": "POST",
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "url": "http://MYAPIWEBSITEURL/app-api-v3/get-new-orders",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJyaW5nMmJyaW5nLm5sIiwiaWF0IjoxNDY0ODIwMjgzLCJleHAiOjE3ODAzNTMwODMsImRhdGEiOnsidXNlcl9pZCI6IjEiLCJsb2NfaWQiOiIzNCIsImFwaSI6ImphNGYzZGM2MzJiNjlkZWM3MzA0MmMxZWU2NmNjMmYwIiwicm9sZSI6ImFkbWluIiwiZGVsY29tcF9pZCI6ZmFsc2V9fQ.TFAf-jSDOnKm0wHvPWuj8h5lumd1M6LAw87q-gPkcAs"
    }
  },
  "statusText": ""
}

奇怪的是,这只发生了一次。当我在错误后再次进行呼叫时,我得到的数据没有错误。

这让我感到很沮丧,所以我把方法从POST更改为GET,现在我看到我不再收到数据错误,每次收到数据时,我都试过200次。

我不明白这种行为。在web-view上,所有调用工作,POST和GET。但是在iOS设备上,POST请求有时会返回错误,并且使用GET它永远不会返回错误

我的服务:

    this.setNewOrders = function () {
    $ionicLoading.show({ template: '<ion-spinner icon="ios"></ion-spinner><p style="margin: 5px 0 0 0;">Getting new orders..</p>'});
    newOrders = false;
    return $http({
        url: api_url + "/get-new-orders",
        method: 'GET',
        headers: {'Content-Type':'application/x-www-form-urlencoded'}
    }).then(function (response) {
        //console.log(response.data)
        if (response.data.status == 'success') {
            if (response.data.returnData.length > 0) {
                //set unixtime
                angular.forEach(response.data.returnData, function (value, key) {
                    //set time elapsed
                    var momentDate = moment(value.order_created);
                    value.dateMiliseconds = momentDate.unix() * 1000;
                });
                newOrders = response.data.returnData;
            }
        }
        $ionicLoading.hide();
        return response.data;
    });
}

0 个答案:

没有答案
相关问题