-2

i have this in my view so that the people go example, view/1 i get via restful all the data of that user and i parse that in html with a table, Im using cakephp,i don't want to use angularJS, there's a JQuery library that do that job, do you know the name?

 <script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("/social/users.json")
    .success(function (response) {$scope.users = response.users;});
});
</script>

then i receive this answer

{
    "user": [
        {
            "id": 1,
            "email": "email",
            "name": "name",
            "last_name": "last",
            "username": "itsme",
            "password":"password",
            "created": "2015-09-21T16:44:47+0000",
            "modified": "2015-09-21T16:52:08+0000"
        }
    ]
}

how can i parse repeating this code and populate data in html?

   <div ng-app="myApp" ng-controller="customersCtrl"> 

<table>
  <tr ng-repeat="x in users">
    <td>{{ x.name }}</td>
    <td>{{ x.last_name }}</td>
  </tr>
</table>

</div>
  • take a look at this answer http://stackoverflow.com/questions/9541570/display-all-items-in-array-using-jquery – cesara Sep 21 '15 at 20:16

1 Answers1

0

Two things: first, you don't need to specify the content-type in the beforeSend. $.ajax has a specific contentType property you can use, and by default it is already "application/x-www-form-urlencoded; charset=UTF-8'.

Second, use dataType property of $.ajax. You can use dataType: 'json' and then the response you get in the success function will be alaready json parsed object -or just a js object-.

From there you can access all the properties, arrays, whatever, from this json parsed response as you were working with any other normal javascript object.

MarkSkayff
  • 1,334
  • 9
  • 14
  • Well, you should know how the parse a js array, or learn it yourself. Also you can look for in google how to populate HTML with, let's say, JQuery or Javascript directly. – MarkSkayff Sep 22 '15 at 18:05