$ http get with error returning json to

I am working on a fairly simple cord application to sync documentation from server to application

I am targeting ios and android

I am working with ionic framework, angularjs, cordova

Here is the code for my http:

$http.get("http://[my_server]/fmd/collections", {})
  .success(function(response) {
      console.log(response);
      if (response.code != 0) {
        $ionicLoading.hide();
            $ionicPopup.alert({
                title: 'An error occured',
                template: response.message
            });
        }
        else  {
          console.log('TODO corriger ca !!!');
          response.collections.forEach(insertCollection);
      }
  })
  .error(function(data, status, headers, config) {
    console.log('hey');
    console.error(data);
    console.error(status);
    console.error(headers);
    console.error(config);
    $ionicLoading.hide();
  })
  .finally(function() {
    console.log("Update process end");
      Collections.all().then(function(collections){
        console.log('pwet');
        $scope.collections = collections;
      }); 
      $ionicLoading.hide();
  });

      

Server-Side Code (PHP) (mostly hardcoded)

function collectionsAction() {
    print header("Access-Control-Allow-Origin: *");
    print header("Content-Type:application/json");

    $response = new stdClass();
    $response->code = 0 ;
    $response->message = "OK" ;
    $response->collections = array() ;

    $collection = new stdClass();
    $collection->id = 1;
    $collection->model = "my model";
    $collection->revision = "014";
    $collection->date = "March, 18th 2013";
    array_push($response->collections, $collection);

    print json_encode($response);
}

      

It works well in debug mode in chrome It works great in Android But It doesn't work on the iOS emulator, I get the following trace in the log:

2015-04-21 14:57:58.516 AppDoc[94712:1924602] hey
2015-04-21 14:57:58.516 AppDoc[94712:1924602] ERROR: null
2015-04-21 14:57:58.516 AppDoc[94712:1924602] ERROR: 0
2015-04-21 14:57:58.517 AppDoc[94712:1924602] ERROR: 
2015-04-21 14:57:58.517 AppDoc[94712:1924602] ERROR: {"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://[my_server]/fmd/collections","headers":{"Accept":"application/json, text/plain, */*"}}

      

It also doesn't work on ios device.

I'm sure there is something obvious, but I can't seem to find it ...

Thank!

+3


source to share





All Articles