kill all ongoing XHR requests
$('#search-box').keyup(function() { // bind the search data var input = $('.search-input').val();
$.getJSON({ // get JSON data
url: 'example/query.php?keyword=' + input,
//pre-load
beforeSend: function() {
$(".search-lists").html("<span class='loading'><img src='_/images/loading.gif' /></span>");
},
success: function(data) {
if (input.length >= 3) { // limit keyword to >=3
var output = "<ul class='search-lists'>"; //output search data list
$.each(data, function(key, val) {
output += '<li>';
output += '<a>' + val.term + '</a>';
output += '</li>';
});
output += '</ul>';
$('.search-results').html(output);
console.log('load ajax');
} // end if
else {
console.log('kill ajax');
}
}
}); // JSON request
}); // data bind