django - $http success function does not execute in Angular js -


i trying http response django local server returns json response.

json response:

[{"fields": {"dob": "2015-05-08", "image": "media/jainsubh_1394437734_6.png", "text_file": "my_txt_files/jn2i0oq.png", "usr_name": "ankitmishra", "email": "anbishamar@gmail.com"}, "model": "my_fr_app.new_user_reg", "pk": 15}] 

angular code is:

<!doctype html> <html> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <body>  <div ng-app="myapp" ng-controller="customersctrl">   <ul>   <li ng-repeat="x in items">     {{ x.usr_name  }}   </li> </ul>  </div>  <script> var app = angular.module('myapp', []); app.controller('customersctrl', ['$http',function($http) {   $http.get("http://127.0.0.1:8000/members")   .success(function (response) {     this.items = response.data.fields;   }]); }); </script>  </body> </html> 

i don't know why success callback not executes !! though server returns response code 200 & 304 means request being executed .

just post alternative, fun, using controlleras functionality in angular.

<div ng-app="myapp" ng-controller="customersctrl vm">   <ul>   <li ng-repeat="x in vm.items">     {{ x.usr_name  }}   </li> </ul>  </div>  <script>     var app = angular.module('myapp', []);     app.controller('customersctrl', ['$http', '$scope',function($http, $scope) {         var vm = this;  // closure issues.  using controlleras functionality, there no need go $scope @ all.         $http.get("http://127.0.0.1:8000/members")             .success(function (response) {                 vm.items = response.data.fields;         });     }]); </script> 

http://toddmotto.com/digging-into-angulars-controller-as-syntax/


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -