I am trying to stop displaying some data in table while I am typing text in website inbox.
I have event keyup whitch searches some data in database and then displays it on website. But when somebody is typing longer text an event is fired as many times an many letters is being typed. I want to cancel last event when another sign is typed so only last event will display correct data.
righ now when I type some text fast I get displayed data twice or even more....
the code I use (simplified version) is below...
Can someboty suggest how can I sole it?
$( "#SAPdescription" ).keyup(function() {
// Clear table
$('#tblListSAP tbody').empty();
if($('#SAPdescription').val().length >= 3)
{
$.ajax({
type: "POST",
url: "php/list_SAP.php",
data: {
SAPdescription: (!$('#SAPdescription').val()) ? "NULL" : $('#SAPdescription').val()
},
success: function(msg){
if(msg.substr(0,5) == 'ERROR')
{
error(msg);
}
else
{
if(xmlRoot = getXML(msg))
{
var rows = $(xmlRoot).find('row');
for(var i=0 ; i<rows.length ; i++)
{
var tr = $('<tr></tr>');
tr.append($('<td></td>').text(rows.eq(i).find('sapdescription').eq(0).text()));
$('#tblListSAP tbody').append(tr);
}
}
else
{
error('No data in received XML file!');
}
}
},
error: AjaxErrorFunction
});
}
});