Using an ajax request I receive the following json data:
{
"status" : "success",
"xplist" : [
{ "rank" : "1", "username" : "test1", "xp" : "2500" },
{ "rank" : "2", "username" : "test2", "xp" : "2200" },
{ "rank" : "3", "username" : "test3", "xp" : "1900" }
]
}
In my controller I created empty data variable
$scope.data = {};
And assign the json data to it like this:
$scope.data.xpresult = data;
Then in my view I try to use ng-repeat to get the items out:
<li ng-repeat="xp in data.xpresult.xplist">
<div class="listItem">
<div class="left">
<p>{{xp.rank}}</p>
</div>
<div class="middle">
<p style="padding: 8px 46px 0px 0px;margin:0">{{xp.username}}</p>
<p style="margin:0px">{{xp.xp}}</p>
</div>
</div>
</li>
I also tried the to repeat the following instead:
data.xpresult.0.xplist
Also tried to put the data in a variable and stringify the result again:
var xpdata = JSON.parse(data);
$scope.data.xpresult = JSON.stringify(xpdata.xplist);
But unfortunately this didn't work either.
Can anyone give me a pointer on how to get this out properly or what I am doing wrong?
Update
The controller is as following:
angular.module('AndriodApp')
.controller('ExperienceController', function($scope,md5){
$scope.data = {};
$scope.getTop50 = function(uid,uname) {
var token = md5.createHash("test"+uid+uname+"test");
var postdata = { messagetype: "getexperience", userid: uid, securitytoken: token };
$.post("http://127.0.0.1/backend/jiomsg.php",postdata)
.done(function( data ) {
alert( "Data Loaded: " + data );
$scope.data.xpresult = data;
});
}
$scope.getTop50("1","Gerard");
});