Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Delay load of data for 2 seconds in jQuery ajax

I'm loading the search results via jQuery ajax in a div container. I would like the results to be shown to the user after a 2 second delay or after the user has entered at least 3 letters/characters in the textbox to search. How would I do this?

jQuery code:

$(".bsearch").keydown(function() {
  //create post data
  var postData = { 
    "search" : $(this).val()

  //make the call
    type: "POST",
    url: "quotes_in.php",
    data: postData, 
    success: function(response){
like image 668
input Avatar asked Aug 16 '10 21:08


People also ask

How do you call Ajax every 5 seconds?

The jQuery code to call AJAX in every 5 secondsready(function(){ sendRequest(); function sendRequest(){ $. ajax({ url: "example. php", success: function(data){ $('#listposts').

What is the default timeout for jQuery AJAX?

The default value is 0 , which means there is no timeout.

Is Ajax slow?

In sites that rely upon Ajax for functionality (or even pizzazz), performance becomes even more critical than the general JavaScript performance. Because Ajax requests take place behind the scenes, to the end user there is little discernible difference between an Ajax request being slow, and nothing happening at all.

1 Answers

Use this function:

setTimeout(function() {
}, 2000);
like image 198
meder omuraliev Avatar answered Oct 01 '22 04:10

meder omuraliev