0

I am using the following script to get data from a Google Spreadsheet. From time to time the spreadsheet will be 'turned off' and the script will result in an error 403. I want to know how to check for that error and trigger another function when it does.

function loadJSON0() {
    $(function checkJSON0() { 
        $.getJSON( https://spreadsheets.google.com/feeds/list/SPREADSHEETKEY/1//public/values?alt=json-in-script&callback=?,
        function (data) {
            $.each(data.feed.entry, function(i,entry) {
                // do stuff
            });
        });
    });
};

1 Answers1

0

Posible duplicate : Error handling in getJSON calls

$.getJSON("https://spreadsheets.google.com/feeds/list/SPREADSHEETKEY/1//public/values?alt=json-in-script&callback=?", function() {
    $.each(data.feed.entry, function(i,entry) {
        // do stuff
    });
})
.error(function() { alert("error"); });
La masse
  • 1,190
  • 1
  • 10
  • 24
  • this solution throws an additional error. "Uncaught SyntaxError: Unexpected token ." – Joshua Hess Oct 05 '17 at 10:34
  • Please proide the whole error. Also can you provide the entire http response? – La masse Oct 05 '17 at 10:49
  • the original error appears as: jquery.min.js:4 GET https://spreadsheets.google.com/feeds/list/14nscmFGq1EEaXBT0ybSqar_ij3d1_SnusbeJSXR9aH4/1/public/values?alt=json-in-script&callback=jQuery32109224964495020795_1507201568433&_=1507201568434 net::ERR_ABORTED – Joshua Hess Oct 05 '17 at 11:07