rlc
rlc

Reputation: 6069

Wait for response with $.getJSON()

I'm (trying to) using JSON with PHP.

I want to plot a graph using this plugin: http://www.jqplot.com The problem is: It's being plot before the new data arrives. Is there anyway to make jQuery wait for the $.getJSON() and the plot it?

myArray and title are the new data that will be used later.

$.getJSON('./ajax/refreshData.php', function(data) {
    myArray = data.arrayName;
    newTitle = data.newTitle;
});

plot1 = $.jqplot('divname', [ myArray ], {
    series : [ {
    renderer : $.jqplot.BarRenderer} ],
    title : newTitle,

...

Upvotes: 1

Views: 3998

Answers (1)

Reigel Gallarde
Reigel Gallarde

Reputation: 65264

$.getJSON('./ajax/refreshData.php', function(data) {
    myArray = data.arrayName;
    newTitle = data.newTitle;
    plot1 = $.jqplot('divname', [ myArray ], {
       series : [ {
       renderer : $.jqplot.BarRenderer} ],
       title : newTitle,
});

Upvotes: 3

Related Questions