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
$.ajax({
type: "POST",
url: "quotes_in.php",
data: postData,
success: function(response){
$("#left").html(response);
$("div#smore").hide();
}
});
The jQuery code to call AJAX in every 5 secondsready(function(){ sendRequest(); function sendRequest(){ $. ajax({ url: "example. php", success: function(data){ $('#listposts').
The default value is 0 , which means there is no timeout.
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.
Use this function:
setTimeout(function() {
$('#left').html(response);
}, 2000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With