44 CHAPTER 2 THE NUTS AND BOLTS (Personal web server)
44 CHAPTER 2 THE NUTS AND BOLTS OF AJAX In the example HTML code, there is a buttonthat when pressed calls the function StartIt. The function StartIt generates output in the HTML code of the variable counter. The variable counter is a counter that is incremented. To start the timer, the method window.setTimeout needs to be called. The method setTimeout starts a one-time timer that executes the JavaScript represented by the first parameter. The second parameter represents the number of milliseconds that should pass before the JavaScript is executed. It is important to realize that the JavaScript executed is a text-based script and should not reference variables that are not in scope. To generate a repeating timer, the JavaScript calls the function StartIt. Then for each time-out (1 second), the timer countdown is started again. The timer is not started after the counter has reached a value of 10. Periodic Timers The other type of timer is a periodic timer that executes every n milliseconds. Using a periodic timer in JavaScript is similar to using a one-shot timer except the method call is different. Following is the HTML code used to run a periodic timer:
| Counter | No Result |
Note: If you are looking for cheap webhost to host and run your apache application check Vision apache web hosting services