4
I’m doing a search suggest where after the user type at least 4 letters in the input he does via Ajax the search with the suggestions for the user. But currently after the user has typed the first 4 letters of the word a new Ajax request is made for each typed letter and I would like the Ajax requests to be made only after the user has stopped 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>