Open In App

How to set timeout for ajax by using jQuery?

In web programming, the Ajax is used so that the resultant data is shown in the one part of the web page, without reloading the page. The user needs to perform the Ajax request and wants the result within a timeframe. In this scenario, the jquery timeout feature is used in the code. Session timeout has been a very common feature in Ajax-based web applications.

In responsive interface, the programmer needs to delay the ajax request to achieve some task before the response. This can be achieved by using jQuery setTimeout() function. This function executes the given Ajax code after some amount of given time.



Syntax :

Parameters:



Below example illustrates the approach:

Example 1:

Program:

Output :

Example 2: The setTimeout() is a jQuery function which executes a code snippet after delaying a specific time limit. For example, delaying a popup window for a specific time limit, for a user visiting some website. This method accepts a pointer to a function as its first parameter. In this example, delay the Ajax code for 4 seconds using the setTimeout() method.

Code snippet :

Program:

Article Tags :