您应该检查该值是否随时间变化:
var searchRequest = null;$(function () { var minlength = 3; $("#sample_search").keyup(function () { var that = this, value = $(this).val(); if (value.length >= minlength ) { if (searchRequest != null) searchRequest.abort(); searchRequest = $.ajax({ type: "GET", url: "sample.php", data: { 'search_keyword' : value }, dataType: "text", success: function(msg){ //we need to check if the value is the same if (value==$(that).val()) { //Receiving the result of search here } } }); } });});编辑:
searchRequest添加该变量是为了防止对服务器的多个不必要的请求。



