i am running this code when data is typed in a text input:
$("input#search").live("keyup", function(e) {
var search_string = $(this).val();
var i = 0;
var trHTML = '';
if(search_string !== '') {
$.ajax({
type: "POST",
dataType: "json",
url: "/section/search_go",
data: { query: search_string },
cache: false,
success: function(response) {
$.each(response, function(i, item) {
trHTML += '<tr>';
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);
}
});
console.log(i);
}
/*if(counter === 0 || search_string == '') {
$('#customers').html('<tr><td colspan="4">No Results</td></tr>');
}*/
});
i am trying to get the number of records in the $.each loop but i cannot seem to do that.
i have tried using i which is in the function and i also tried adding a counter variable and for each loop i added counter++ but that still isnt working