AngularJS ajax with PHP json return -


i new php , angularjs >< trying using ajax data php fail

here's controller

angular.module('aa')     .controller('expcontroller', ['$scope', 'record', '$http', function ($scope,record, $http) {     $scope.trans = [];     $scope.trans = record.all(); }]); 


factory.js

    angular.module('aa')     .factory('record', ['$http',function recordfactory($http){       return{         all: function(){             return $http.get("./php/getdata.php").success(function (response) {               return  response;             });         }       } }]); 


./php/getdata.php

<?php header("content-type: application/json; charset=utf-8"); $response=       ' [         {id: 0, title: "help", date: "1288323623009", cost: 20, person:"hard", category:"angu", items:[ {name:"item1"},{name:"item2"},{name:"item3"}]},         {id: 1, title: "hahah", date: "1288323623008", cost: 9.99, person:"leo", category:"adv"}       ]';  echo ($response); ?> 

console said

syntaxerror: unexpected token i
@ object.parse (native)
@ fromjson.....

is json format wrong?

your response isn't json, json parser in browser failing.

property names must strings. strings must delimited double quotes.

{id:{"id": (and on other properties).

use a linter test json.

don't write json hand. create php data structure , pass through json_encode.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -