php - AngularJS $resource can't deserialized array into an object -
i'm working php tonic , angularjs. have angular call rest resource. code of rest this:
/** * @method */ public function getdata(){ $response = new response(); $response->code = response::ok; $response->body = array("one","two"); return $response; }
on backend, code return response object array in body. angular use $resource service call backend:
return { getbackdata : function(){ var call = $resource('/table_animation_back/comunication'); call.get(function(data){ console.log(data); }); } }
the result of console.log this:
resource {0: "a", 1: "r", 2: "r", 3: "a", 4: "y", $promise: d, $resolved: true}0: "a"1: "r"2: "r"3: "a"4: "y"$promise: d$resolved: true__proto__: resource
i tried use:
call.query(function(){...})
but response in php object , not array, in way got javascript error. can't access array. wrong?
you need serialize array json before sending client:
public function getdata(){ $response = new response(); $response->code = response::ok; // encode response: $response->body = json_encode(array("one","two")); return $response; }
Comments
Post a Comment