如何在angularjs的ajax成功调用中将数据分配给变量?

时间:2017-04-07 12:05:11

标签: javascript angularjs ajax

您好我正在开发Angularjs应用程序。在ajax调用中,我正在获取数据,我想将该数据分配给变量,但我将数据作为[对象对象]。 以下是我得到的数据

private void MyCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (myCombobox.SelectedItem != null)
        if (myCombobox.SelectedItem.ToString().Equals("Test1"))
        {
            testGrid.Visibility = Visibility.Visible;
        }
        else if (myCombobox.SelectedItem.ToString().Equals("Test2") || myCombobox.SelectedItem.ToString().Equals("Test3"))
        {
            testGrid.Visibility = Visibility.Hidden;
        }
    }
}

以下是我的代码,

{"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"}

任何帮助将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:0)

假设您的代码在控制器中

的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>