I am encountering an issue with a string I receive from an AJAX response:
[{
id: "Abc",
name: "ABCDD",
color: "rgba(203,170,92,0.6)",
div_class: "hotel_name"
}, {
id: '136',
name: 'PBss'
} ]
When I assign this string statically to a variable, it works fine. However, when I retrieve the same string from an AJAX request and use it in a variable, it does not work. Here is the code snippet causing the problem:
Code that is not working:
$http.post(urls)
.success(function (response) {
var x = JSON.parse(response);
$scope.data = x;
}).error(function (data, status, headers, config) {
console.log('error');
});
Working code snippet:
$http.post(urls)
.success(function (response) {
var x = [{
id: "Abc",
name: "ABCDD",
color: "rgba(203,170,92,0.6)",
div_class: "hotel_name"
}, {
id: '136',
name: 'PBss'
} ];
$scope.data = x;
}).error(function (data, status, headers, config) {
console.log('error');
});
I am struggling to identify the cause of this issue. Any assistance would be highly appreciated. Thank you in advance.