AJAX Made Easy - Learn AJAX



JavaScript Tutorials

 
Home JavaScript
 

JavaScript Timers for Ajax

 

The asynchronous function in Ajax establishes a single point connection from the server to the user interface in the browser. Developers have to work with this setting despite the number of functions that it has to execute “at the same time”.


For the users, the function is executed at the same time but they are actually written asynchronously and are being lined up for execution when triggered by the user. The advantage of this single line of connection is that fact that developers can outline the reaction of each coding. The server will also have the chance to focus on a single command even for a very short time.


There are three types of JavaScript timers that could be executed in Ajax. Without Ajax, these JavaScript timers still ensure proper execution of coding in a JavaScript environment:


var id = setTimeout(function, delay); This timer is only triggered once and the coding establishes a delay in the set of function. Developers usually add a delay in the function when they are waiting a command from another function. This timer requires an answer from the server in the form of unique ID. This ID is required so that the client side will know that the transaction is complete and will never execute the function again after a certain delay. The function, delay and together with the ID ensures that only the specific part of the webpage will receive the update.


var id = setInterval(function, delay); This timer works at the same way as the previously indicated timer. However, developers will have the ability to continuously call on the server. The unique ID is still required but it will continue to execute even with the unique ID received. The timer function will only stop when they are manually cancelled by the user. This is an advantage for developers who are working in a server push setting since the information will be continuously requested in an Ajax based setting.


clearInterval (id); With this function, developers will have the ability to stop the timer indicated in the previous functions. The (id) refers to the unique ID received by the client side to indicate that the intended action from the server has been received.


The minimum interval and delay in these timers are at a minimum of 10ms. This will give the server more time to breathe and execute the first function first before receiving another request from the client side. 10ms is a very short amount of time for the naked eye that any user will never know the difference.


The goals of the developers in using JavaScript timers are twofold: first, developers, in choosing to use JavaScript timers, enable the server to understand the function better since it does not concentrate in too many functions at the same time. Secondly, it provides simplification in the midst of complicated coding. Developers can lay out the entire program and easily understand what functions go first while others are being queued for execution.



Read Next: JavaScript Type Attribute



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links