Anand jain Anand jain - 6 months ago 17
AngularJS Question

How to get object array value from response array

How to get object array value from response array? Below is my code to send Ajax request

var post_data = {
"user_name_title" : $scope.user_name_title,
};
$http.post(url,post_data).then(function(res)
{
console.log(res['Message']);
},


Output is

{
"ResponseCode": 200,
"Data": [],
"Message": "Data inserted successfully.",
"Error": []
}


How can I get the result objects, I have used


console.log(res['Message']);


but it showing undefined. What should I use?

Answer

As you are using .then over $http method, you should get API response data inside data property of response object, like below.

console.log(res.data['Message']);