0

I have a JSON object that contains a value I want to automatically update on my webpage. The JSON object is being retreived from a google sheets file using:

function getData() {
    return $.ajax({
        url: 'https://spreadsheets.google.com/feeds/cells/1r56MJc7DVUVSkQ-cYdonqdSGXh5x8nRum4dIGMN89j0/1/public/values/R29C4?alt=json-in-script&callback=importGSS',
        dataType: 'jsonp',
        jsonpCallback: 'importGSS'
    })
}

var obj;
getData().done(function (data) {
  obj = data;
});

(Thanks to user Andy for this!)

I can access the value by obj["entry"]["content"]["$t"] but I am not sure how to add this value to my paragraph element so that it automatically updates when the value changes in the object.

Could someone explain the best way to do this?

Thank you

3
  • 1
    The general way: $('p').html(obj["entry"]["content"]["$t"]); Commented Oct 2, 2014 at 11:04
  • I have definitely seen this object's structure here 15 minutes ago... Commented Oct 2, 2014 at 11:05
  • OK great I've got it now. Thanks guys! Commented Oct 2, 2014 at 11:31

1 Answer 1

1

How about this?

function getData() {
    return $.ajax({
        url: 'https://spreadsheets.google.com/feeds/cells/1r56MJc7DVUVSkQ-cYdonqdSGXh5x8nRum4dIGMN89j0/1/public/values/R29C4?alt=json-in-script&callback=importGSS',
        dataType: 'jsonp',
        jsonpCallback: 'importGSS',
        success: function(data) {
            // p being the element that you want to put your data in
            $('p').html(data["entry"]["content"]["$t"]);
        }
    })
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply, yes this could work. The only issue is I have around 50 values to put into seperate divs in the actual spreadsheet so idealy I would want to asign each value to a variable with a semantic name in the javascript first to make the code easier to read.

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.