Guest User

Untitled

a guest
Aug 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. This javascript setTimeout interacts with ajax requests in a really weird way
  2. function progres_import() {
  3. //if(import_status != 'finalizat') {
  4. alert("progres_import");
  5. setTimeout(function() { return update_progres_import(); }, 2000);
  6. setTimeout(function() { return update_progres_import(); }, 4000);
  7. setTimeout(function() { return update_progres_import(); }, 6000);
  8. setTimeout(function() { return update_progres_import(); }, 8000);
  9.  
  10. //setTimeout(function() { progres_import(); }, 400);
  11. //}
  12. //else {
  13.  
  14. //}
  15. }
  16.  
  17. var xmlhttp_import_progres;
  18. function update_progres_import() {
  19. xmlhttp_import_progres=GetXMLHttpObject();
  20. if (xmlhttp_import_progres==null) {
  21. alert ("Browser does not support HTTP Request (xmlhttp_import_progres)");
  22. return;
  23. }
  24.  
  25. var url="crm/ferestre/import_progres.php";
  26. url=url+"?sid="+Math.random();
  27.  
  28. xmlhttp_import_progres.onreadystatechange=function() {
  29. if (xmlhttp_import_progres.readyState == 4) {
  30. progres_resp = xmlhttp_import_progres.responseText;
  31. progres = progres_resp.split('_');
  32. import_nrc = progres[0];
  33. import_nrt = progres[1];
  34. import_status = progres[2];
  35. mesaj = 'Progres import: ' + import_nrc + ' / ' + import_nrt;
  36. //document.getElementById("corp_import_mesaj").innerHTML = mesaj;
  37. alert(progres_resp);
  38. }
  39. };
  40. xmlhttp_import_progres.open("POST",url,true);
  41. xmlhttp_import_progres.send(null);
  42. }
  43.  
  44. function progres_import() {
  45. //if(import_status != 'finalizat') {
  46. alert("progres_import");
  47. setTimeout(function() { return update_progres_import(0); }, 2000);
  48. setTimeout(function() { return update_progres_import(1); }, 4000);
  49. setTimeout(function() { return update_progres_import(2); }, 6000);
  50. setTimeout(function() { return update_progres_import(3); }, 8000);
  51.  
  52. //setTimeout(function() { progres_import(); }, 400);
  53. //}
  54. //else {
  55.  
  56. //}
  57. }
  58.  
  59. var xmlhttp_import_progres = [];
  60. function update_progres_import(i) {
  61. xmlhttp_import_progres[i]= GetXMLHttpObject();
  62. if (xmlhttp_import_progres[i]==null) {
  63. alert ("Browser does not support HTTP Request (xmlhttp_import_progres)");
  64. return;
  65. }
  66.  
  67. var url="crm/ferestre/import_progres.php";
  68. url=url+"?sid="+Math.random();
  69.  
  70. xmlhttp_import_progres[i].onreadystatechange=function() {
  71. if (xmlhttp_import_progres[i].readyState == 4) {
  72. progres_resp = xmlhttp_import_progres[i].responseText;
  73. progres = progres_resp.split('_');
  74. import_nrc = progres[0];
  75. import_nrt = progres[1];
  76. import_status = progres[2];
  77. mesaj = 'Progres import: ' + import_nrc + ' / ' + import_nrt;
  78. //document.getElementById("corp_import_mesaj").innerHTML = mesaj;
  79. alert(progres_resp);
  80. }
  81. };
  82. xmlhttp_import_progres[i].open("POST",url,true);
  83. xmlhttp_import_progres[i].send(null);
  84. }
Add Comment
Please, Sign In to add comment