0

I am attempting to access data from a Google Spreadsheet, however, I am having difficulty getting the code to work.

I was able to add data to the spreadsheet by using API Spreadsheets and the following code:

function SubForm (){
            $.ajax({
                url:'<API>',
                type:'post',
                data:$("#myForm").serializeArray(),
                success: function(){
                  alert("Form Data Submitted. Please log in.")
                },
                error: function(){
                  alert("There was an error")
                }
            });
        }

However, I can't seem to access the data using similar code. The website I am using for the API provides the following sample code for reading data, however, I am not sure what to make of it and how to implement it.

fetch("<API>").then(res=>{
    if (res.status === 200){
        // SUCCESS
        res.json().then(data=>{
            const yourData = data
        }).catch(err => console.log(err))
    }
    else{
        // ERROR
    }
})

Any help would be appreciated. Thanks!

  • `const yourData = data` -- `yourData` is only available inside the `then` callback. – evolutionxbox Jan 17 '21 at 11:29
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – evolutionxbox Jan 17 '21 at 11:30

0 Answers0