javascript - How to return json from google script url -


this question has answer here:

i want json value in timeline_json of following line

          window.timeline = new vco.timeline('timeline-embed', new vco.timelineconfig(timeline_json)); 

the above line in document.ready

to timeline_json, i've written function. i'm pasting code in exact order of code.

function get_json(){   $.getjson("https://script.google.com/macros/s/file_id/exec", function(data) {   console.log(data);     return data;  }); }   var timeline_json=get_json();  console.log(timeline_json)    window.timeline = new vco.timeline('timeline-embed', new vco.timelineconfig(timeline_json)); 

in console, i'm getting object in order

undefined timeline.js:2950 uncaught invalid  index.html:78 object {title: object, events: array[18]} 

if object first, work.

an ajax request async default (and should be). cannot return value ajax request callback. can returning promise (ajax request) method , use relevant deferred method, e.g done():

function get_json() {     return $.getjson("https://script.google.com/macros/s/file_id/exec"); }  get_json().done(function (data) {     window.timeline = new vco.timeline('timeline-embed', new vco.timelineconfig(data)); }); 

Comments