AngularJS $http call not outputting Array -


trying grab associative array through angularjs $http call, instead of getting actual array, getting string "array".

here $http call:

$http({             method : 'post',              url : '[myphpfile].php',              data : 'data=' + $scope.placementid,             headers : { 'content-type' : 'application/x-www-form-urlencoded' }         }).success(function(data) {             alert(data);         }); 

and [myphpfile].php (omitted other lines):

echo somefunctioninanotherfile($_post['data']); 

i know grabbing array because doing echo var_dump(thearray) in [myphpfile].php , alert(data) in success part of $http call, get:

array(8) {     ["id"]=> string(1) "2"     ["id_key"]=>    string(1) "2"    ... } 

but without var_dump, , alert(data["id"]) under success, nothing happens. , doing alert(data[1]) "r", not sure why returned data becomes string called "array".

i have tried echo json_encode(...) in[myphpfile].php , alert(json.parse(data)) under success, didn't work either.

just trying access simple array, need help. :(

a few issues here.

json_encode() php should work, make sure header set correctly.

<?php     header('content-type: application/json');     echo json_encode(somefunctioninanotherfile($_post['data'])); ?> 

the second issue json_encode turn php "array" object if array "associative" array , regular array otherwise.

lastly, displaying raw post data incredibly dangerous , should not it.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -