You can use setTimeout
to delay an action for a set number of milliseconds. You can also clear the timeout to prevent requests being queued up if someone types quickly. Try this:
var timer;
function Search() {
clearTimeout(timer) // clear the request from the previous event
timer = setTimeout(function() {
$.ajax({
// ...
});
}, 200);
}
Note I made the delay 200ms which is normally more than enough time for someone to have typed several keys, but quick enough that it would not appear too slow for the UI to update.