how to load data step by step with ajax for big data without stopping the display of the webpage

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:



  1. $.when (
  2. $.ajax({url:"load.php"})
  3. .done ( function (data)
  4. {
  5. responsive_INTRODUCTION();
  6. }),
  7. $.getJSON(url0, function (data) {
  8.   str_r=data.paragraphes[0].split("-");
  9.   str_g=data.paragraphes[1].split("-");
  10.   str_b=data.paragraphes[2].split("-");

  11. })
  12. ,
  13. $.getJSON(url1, function (data) {
  14.   str1_r=data.paragraphes[0].split("-");
  15.   str1_g=data.paragraphes[1].split("-");
  16.   str1_b=data.paragraphes[2].split("-");

  17. })
  18. ,
  19. $.getJSON(url2, function (data) {
  20.   str2_r=data.paragraphes[0].split("-");
  21.   str2_g=data.paragraphes[1].split("-");
  22.   str2_b=data.paragraphes[2].split("-");

  23. })  
  24. ).always (function()     
  25. {


  26. for (var i=0;i<str_r.length;i++)
  27. {
  28. pixout2[i*4  ] = str_r[i];
  29. pixout2[i*4 +1 ] = str_g[i];
  30. pixout2[i*4 +2 ] = str_b[i];
  31. pixout2[i*4 +3 ] = 255;
  32. }
  33. contextout2.putImageData(imgdout2, 0, 0);
  34. animate_BRANDING();
  35. });

....

That is why my idea is to do that loading only the first:
  1. $.when (
  2. $.ajax({url:"load.php"})
  3. .done ( function (data)
  4. {
  5. responsive_INTRODUCTION();
  6. }),
  7. $.getJSON(url0, function (data) {
  8.   str_r=data.paragraphes[0].split("-");
  9.   str_g=data.paragraphes[1].split("-");
  10.   str_b=data.paragraphes[2].split("-");

  11. })  
  12. ).always (function()     
  13. {


  14. for (var i=0;i<str_r.length;i++)
  15. {
  16. pixout2[i*4  ] = str_r[i];
  17. pixout2[i*4 +1 ] = str_g[i];
  18. pixout2[i*4 +2 ] = str_b[i];
  19. pixout2[i*4 +3 ] = 255;
  20. }
  21. contextout2.putImageData(imgdout2, 0, 0);
  22. animate_BRANDING();
  23. });

and 

decomposing the loading in another place 

  1. $(document).ready( function () {


  2. var time_delta=500;
  3. var cpt=0;
  4. var int1=setInterval( function() {
  5. cpt++;
  6. if (cpt==1)
  7. {
  8. $.getJSON(url1, function (data) {
  9.   str1_r=data.paragraphes[0].split("-");
  10.   str1_g=data.paragraphes[1].split("-");
  11.   str1_b=data.paragraphes[2].split("-");
  12.   run_str1=1;
  13.   
  14. });
  15. }
  16. else if (cpt==2)
  17. {
  18. $.getJSON(url2, function (data) {
  19.   str2_r=data.paragraphes[0].split("-");
  20.   str2_g=data.paragraphes[1].split("-");
  21.   str2_b=data.paragraphes[2].split("-");
  22.   run_str2=1;
  23.   
  24. });
  25. }
  26. else {clearInterval(int1);}
  27. },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 )