a_miguel6687
a_miguel6687

Reputation: 529

ajax call on document ready

Im having problems with my ajax call loading on document.ready but when I incorporate a window. scroll function the ajax call is successfully rendered any suggestions on how I can tweak my code. I can't provide a fiddle for this one because I don't no how to include anychart in the fiddle here is a snippet of my code:

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();

});

Upvotes: 1

Views: 3454

Answers (2)

a_miguel6687
a_miguel6687

Reputation: 529

I already noticed the problem with my function and solved it by having the ajax call in the same level where the chart is drawn.what was happening the last time was the chart does get rendered without waiting for the data. leaving the chart empty. so maybe the reason why the scroll function is working is becaused it's forcing the ajax data call when scrolling to the specific part of the page.

Upvotes: 0

Florian M&#252;ller
Florian M&#252;ller

Reputation: 7795

This would be fully working without async: false at the beginning. Why would you want to have an AJAX call not async?

Upvotes: 1

Related Questions