Good evening.

I have a function:

var auto_refresh = setInterval( function AUTOREFRESH2() { $('#ajax').load('checkready.php').fadeIn("slow"); }, ); </script> 

How to make it so that when you press a button, this function works for 5 seconds? Then, as it takes 5 seconds, it would turn off.

  • clearInterval In the question code, the second parameter is omitted in the setInterval call. - Igor
  • Can I write a response code? - TheAs110z
  • What does "function work for 5 seconds"? what function? - Igor

1 answer 1

 function AUTOREFRESH2() { $('#ajax').load('checkready.php').fadeIn("slow"); }); setTimeout(AUTOREFRESH2, 5000); 

This method executes the code (or function) specified in the first argument, asynchronously, with a delay of delay milliseconds.

Unlike the setInterval method, setTimeout executes the code only once.