how to load data step by step with ajax for big data without stopping the display of the webpage
Hello,
I will try to explain my problem:
In my website I load some big data for 3 canvas.
If I load the three, it is long and I need firstly only one.
So my first solution I did isn't good because nothing is display on the page before 3 seconds:
- $.when (
- $.ajax({url:"load.php"})
- .done ( function (data)
- {
- responsive_INTRODUCTION();
- }),
- $.getJSON(url0, function (data) {
- str_r=data.paragraphes[0].split("-");
- str_g=data.paragraphes[1].split("-");
- str_b=data.paragraphes[2].split("-");
- })
- ,
- $.getJSON(url1, function (data) {
- str1_r=data.paragraphes[0].split("-");
- str1_g=data.paragraphes[1].split("-");
- str1_b=data.paragraphes[2].split("-");
- })
- ,
- $.getJSON(url2, function (data) {
- str2_r=data.paragraphes[0].split("-");
- str2_g=data.paragraphes[1].split("-");
- str2_b=data.paragraphes[2].split("-");
- })
- ).always (function()
- {
- for (var i=0;i<str_r.length;i++)
- {
- pixout2[i*4 ] = str_r[i];
- pixout2[i*4 +1 ] = str_g[i];
- pixout2[i*4 +2 ] = str_b[i];
- pixout2[i*4 +3 ] = 255;
- }
-
- contextout2.putImageData(imgdout2, 0, 0);
-
- animate_BRANDING();
-
- });
....
That is why my idea is to do that loading only the first:
- $.when (
- $.ajax({url:"load.php"})
- .done ( function (data)
- {
- responsive_INTRODUCTION();
- }),
- $.getJSON(url0, function (data) {
- str_r=data.paragraphes[0].split("-");
- str_g=data.paragraphes[1].split("-");
- str_b=data.paragraphes[2].split("-");
- })
- ).always (function()
- {
- for (var i=0;i<str_r.length;i++)
- {
- pixout2[i*4 ] = str_r[i];
- pixout2[i*4 +1 ] = str_g[i];
- pixout2[i*4 +2 ] = str_b[i];
- pixout2[i*4 +3 ] = 255;
- }
-
- contextout2.putImageData(imgdout2, 0, 0);
-
- animate_BRANDING();
-
- });
and
decomposing the loading in another place
- $(document).ready( function () {
- var time_delta=500;
- var cpt=0;
- var int1=setInterval( function() {
- cpt++;
- if (cpt==1)
- {
- $.getJSON(url1, function (data) {
- str1_r=data.paragraphes[0].split("-");
- str1_g=data.paragraphes[1].split("-");
- str1_b=data.paragraphes[2].split("-");
- run_str1=1;
-
- });
- }
- else if (cpt==2)
- {
- $.getJSON(url2, function (data) {
- str2_r=data.paragraphes[0].split("-");
- str2_g=data.paragraphes[1].split("-");
- str2_b=data.paragraphes[2].split("-");
- run_str2=1;
-
- });
- }
- else {clearInterval(int1);}
- },time_delta);
I would have believed the first canvas is displayed straight away since it no more wait for the $when.
But it is still very long.
I believed that an ajax being executed on the server
this would not interact with the creation of the DOM on fly.
My question is the following:
How to load data step by step when they are needed
without stopping the display of all the process before any data are loaded?
Thanks
David ( @webtecgeek www.thecacaocafe.com )