ajax调用文件准备好了

时间:2013-10-30 08:49:11

标签: jquery ajax

我在document.ready上加载了ajax调用问题,但是当我合并一个窗口时。滚动功能ajax调用已成功呈现有关如何调整代码的任何建议。我不能为这个提供一个小提琴,因为我不知道如何在小提琴中包含任何图表是我的代码片段:

function DataStreamer(){
    $.ajax({ // then make an AJAX-request
        async: false,
        cache: false,
        url: '/APAC/TW/Resources/js/gethistoricalpricing.js',
        dataType: 'json', // csv data is text
        success: function(resp) { // "resp" variable is a response to AJAX-request
            // Append new data into the 'ds1' data set
            var line = [], json = resp, i= 0;
            for (i; i < resp.length; i++) {

                rawDate = json[i]['Date'].split('/');
                hisDate = rawDate[2] + rawDate[0] + rawDate[1];
                hisPrice = json[i]['Price'];

                line.push("\n"+hisDate + "," + hisPrice);
            }
            chart.appendData('ds_prices', line);
            // getSeriesById method returns 's1' series 'main' chart,
            // you can also use full path to the series through the objectModel, but this way is shorter
            chart.commitDataChanges();
        }
    })


}

$(document).ready(function(){
    DataStreamer();

});

2 个答案:

答案 0 :(得分:1)

在开头没有async: false的情况下,这将完全正常工作。为什么要让AJAX调用不是异步?

答案 1 :(得分:0)

我已经注意到我的函数存在的问题,并通过将ajax调用放在绘制图表的同一级别来解决它。最后一次发生的情况是图表确实在没有等待数据的情况下呈现。把图表留空。因此,滚动功能正常工作的原因可能是它在滚动到页面的特定部分时强制执行ajax数据调用。

相关问题