I'm doing a search Suggest where after the user types at least 4 letters in the input it does via Ajax the search with the suggestions to the user. But currently after the user has entered the first 4 letters of the word a new Ajax request is made to each letter entered and I would like Ajax requests to be made only after the user stops typing in the input. Follow the source:
<script type="text/javascript">
(function(){
'use strict';
$('#search').keyup(function(){
var $this = $(this);
var valueSeach = $this.val()
if(valueSeach.length >= 4){
$.ajax({
url: "consulta.php",
dataType: "json",
data: {
acao: 'autocomplete',
parametro: valueSeach
},
success: function(data) {
response(data);
}
});
}
});
})();
</script>