【问题标题】:Wait for response with $.getJSON()等待响应 $.getJSON()
【发布时间】:2010-08-10 04:11:39
【问题描述】:

我正在(尝试)将 JSON 与 PHP 一起使用。

我想使用这个插件来绘制图表:http://www.jqplot.com 问题是:在新数据到来之前正在绘制它。有没有办法让 jQuery 等待 $.getJSON() 和它的情节?

myArraytitle是后面会用到的新数据。

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

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

...

【问题讨论】:

  • 将 plot1 的赋值移到为 myArray 赋值的回调中

标签: jquery json getjson


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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-03
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 2018-11-02
    • 2011-11-17
    相关资源
    最近更新 更多