1

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.

2
  • 1
    that is a jsonp wrapper. Commented Aug 20, 2015 at 2:16
  • thank you @charlietfl turns out I was getting the json-in-script version for the spreadsheet and I should've just gotten the json version Commented Aug 20, 2015 at 2:34

1 Answer 1

2

For my JSON url, I had "alt=json-in-script" at the end, making it a JSONP and not a JSON. The solution for that was to just replace the end string with "alt=json".

Then to bypass the Cross Origin Request, I used this Chrome extension.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.