javascript - How to assign data to variable in ajax success call in angularjs? -
hi developing angularjs application. in ajax call getting data , want assign data variable getting data as[object object]. below data getting
{"data":{"id":64,"otp":2112},"status":200,"config":{"method":"post","transformrequest":[null],"transformresponse":[null],"url":"http://192.168.0.213:1234/api/checkuser","data":{"firstname":"dfd","lastname":"fdf","gender":"male","dateofbirth":"2017-04-04","nationality":"india","mobile_countrycod":"376","mobilenumber":"444","emailid":"sdsdffffff","ismobileverified":false,"isemailverified":false,"home_location":"q","home_city":"q","home_neighbourhood":"q","home_housenumber":"q","home_mainstreet":"q","home_substreet":"q","work_location":"q","work_city":"q","work_neighbourhood":"q","work_housenumber":"q","work_mainstreet":"q","work_substreet":"q","requestedplatform":"web","requestedlanguage":"english"},"headers":{"accept":"application/json, text/plain, */*","content-type":"application/json;charset=utf-8"}},"statustext":"ok"}
below code,
$http.post('http://192.168.0.213:1234/api/checkuser', registrationdata).then(function (response) { alert(json.stringify(response)); var customerid = response.data.id; var otp = response.data.otp; $state.go('registration.otpverification', response); }
any appreciated. thank you.
assuming code in controller
script.js
angular.module('app', []); angular.module('app') .controller('examplecontroller', ['$scope', function($scope) { $http.post('http://192.168.0.213:1234/api/checkuser', registrationdata).then(function (response) { $scope.customerid = response.data.id; $scope.otp = response.data.otp; } }]);
index.html
<!doctype html> <html lang="en" ng-app="app"> <head> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.min.js"></script> <script src="script.js"></script> </head> <body ng-controller="examplecontroller"> customerid = {{customerid}}, otp = {{otp}} </body> </html>
Comments
Post a Comment