I'm trying to retrieve a JSON from a public Google Spreadsheets page. Originally I tried just doing an AJAX call to it and the data was retrieved but I couldn't save the data to my $scope.
Next I tried the $http.get but ran into cross origin request problems.
My solution then was to use the request module in the backend to get the JSON like so
var request = require('request');
var url = "MY_URL";
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.send(body);
}
})
I put this at an endpoint so from the frontend, I can do the $http.get request onto that url like this
$http.get(url).success(function(data){
console.log(data);
});
However, when I log it to the console, the Chrome inspector can't parse the JSON because the Google Spreadsheet JSON has "gdata.io.handleScriptLoaded(" before the JSON area.
I'm wondering if there's a way to still be able to parse this? Or if there's an easier way to get past the cross origin request problem?
So far I'm thinking of just splicing the string into a valid JSON but I'm sure there's a better way.