i am trying to create a search using multiple jquery functions
i have created this code and functions:
$(document).ready(function() {
var timer = null;
$('input#search').keyup(function(e) {
searchGo();
//clearTimeout(timer);
//timer = setTimeout(searchGo(), 800)
});
//searchGo();
});
function searchGo() {
customersSearch();
contactsSearch();
invoicesSearch();
ticketsSearch();
}
the code above processes the functions on input keyup
i have multiple functions that look like the below, the other functions have the same code but a different URL
function customersSearch() {
var search_string = $("input#search").val();
var trHTML = '';
var resultLength = 0;
$.ajax({
type: "POST",
dataType: "json",
url: "/section/search_go?type=customers",
data: { query: search_string },
cache: false,
success: function(response) {
resultLength = response.length;
if(search_string === '') {
resultLength = 0;
trHTML += '<tr>';
trHTML += '<td colspan="4">No Results</td>';
trHTML += '</tr>';
} else {
$.each(response, function(i, item) {
trHTML += '<tr ' + item.action + '>';
trHTML += '<td>' + item.accountnumber + '</td>';
trHTML += '<td>' + item.company + '</td>';
trHTML += '<td>' + item.phone + '</td>';
trHTML += '<td>' + item.postcode + '</td>';
trHTML += '</tr>';
});
}
$('#customers').html(trHTML);
$("#customers_counter").html("(" + resultLength + ")");
}
});
}
its searching and posting using ajax fine but if i clear the text input and try searching again it seems to take a while for it to finish and search again