开发者

Delay load of data for 2 seconds in jQuery ajax

I'm load开发者_StackOverflow中文版ing 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
  $.ajax({
    type: "POST",
    url: "quotes_in.php",
    data: postData, 
    success: function(response){
      $("#left").html(response);                    
      $("div#smore").hide();
    }
  });


Use this function:

setTimeout(function() {
    $('#left').html(response);
}, 2000);


use this function

function ajax_delay(str){
 setTimeout("str",2000);
}

results will be

 $.ajax({
    type: "POST",
    url: "quotes_in.php",
    data: postData, 
    success: function(response){

        ajax_delay($('#left').html(response));
$("div#smore").hide();
    }
  });

hope this helps you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜