I’m using this code to search by ajax and jquery:
// this is the id of the submit button
$("form#search_form input#key").keyup(function() {
if ( $(this).val().length >=2 ){
var url = base_url()+"welcome/search2"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: { 'key':$("#key").val() }, // serializes the form's elements.
success: function(data)
{
//alert(data); // show response from the php script.
$('#livesearch').html(data);
}
});
return false; // avoid to execute the actual submit of the form.
}
else $("#fonded2").hide();
});
but there is a problem when the user is writing fast.
is there any way to interupt searching when the user enter a new letter after 500ms
1 Answer