-1

I am new to js and ajax. I want a code that calls a disp.php file and display its output in load.php. The ajax code should pass a value from load.php to disp.php and there must be a five second delay between each call.

Basically I want to replace the below php code which will fail due to script timeout. load() and disp() are functions of disp.php

require("disp.php");

for($i = 1; $i <= $pt[1]; $i++)
{
    load($mat,$i);
    disp();
    sleep(5);     
}
fingerprints
  • 2,751
  • 1
  • 25
  • 45

1 Answers1

1

To make an Ajax call from Javascript see this How to make an AJAX call without jQuery?

And to make the call after every five seconds use setTimeout

<script>
   function callLoad() {
       ......write logic to call the PHP file here... 
   } 

   var callCount = 0;

   function callLoop() {
       callLoad();
       callCount ++;

       if(callCount == 5) return; // Stop the loop

       setTimeout(function() {
           callLoop();
      }, 5000); // Wait for 5 second to make the call again

   } 

   window.onload = callLoop; // Start the loop after the page has finished loading
</script>
Community
  • 1
  • 1
harryjohn
  • 656
  • 1
  • 8
  • 25