My Angular get request fails when the JSON data I retrieve contains forward slashes in the data. I'm not sure how to handle such data as specially as I am using $http.get.
Here is the related code:
$http.get(APIroute).
success(function(data, status, headers, config) {
console.log(data);
vm.results = data.SearchResults;
}).
error(function(data, status, headers, config) {
console.log(data);
});
Data with error (retrieved via other means, not angular):
{
"SearchResults": [
{
"PageCount": "1"
},
{
"SEARCHVAL": "ABC Brickworks Food Centre"
},
{
"SEARCHVAL": "ABC Brickworks Market & Food Centre"
},
{
"SEARCHVAL": "ADAM ROAD FOOD CENTRE,\r\n2 ADAM ROAD,\r\nSINGAPORE 283876"
},
{
"SEARCHVAL": "AMOY STREET FOOD CENTRE,\r\nTELOK AYER STREET,\r\nSINGAPORE 069111"
}
]
}
Response Headers:
Access-Control-Allow-Origin:*
Access-Control-Request-Method:GET
Cache-Control:max-age=43200
Connection:keep-alive
Content-disposition:inline; filename=onemap.txt
Content-Encoding:gzip
Content-Type:text/plain
Date:Sat, 26 Sep 2015 03:11:42 GMT
Keep-Alive:timeout=20
Server:nginx
Transfer-Encoding:chunked
Vary:Accept-Encoding
console error log:
SyntaxError: Unexpected token
at Object.parse (native)
at uc (file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:15:480)
at Zb (file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:82:229)
at file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:83:143
at m (file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:7:322)
at cd (file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:83:125)
at d (file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:84:380)
at file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:118:334
at n.a.$get.n.$eval (file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:132:452)
at n.a.$get.n.$digest (file:///Users/kelvinkoh/Work/SoftEng/lib/js/angular.min.js:129:463)
Anyone have any idea on how to handle such errors? Any insights would be appreciated. Thanks in advance.