i have a input where onkeyup function i wanna do a debound, but lodash isn working for that, someone can check if im doing something wrong? this is the input
function autocomplete_usuario_debounced(){
_.debounce(autocomplete_usuario,500);
}
function autocomplete_usuario(ev) {
$("#modal-search").css("height","500px");
if (0 < document.getElementById("buscadora").value.length) {
document.getElementById("auto_usuario").style.visibility = "visible";
var a = {
busqueda: document.getElementById("buscadora").value
};
$.ajax({
type: "POST"
, url: base_url + "/*********/********/"
, cache: !1
, data: a
, success: function (response) {
response = JSON.parse(response);
if(response['success']){
auto_usuario.innerHTML = response['mensaje'];
}
else{
Materialize.toast('I am a toast', 2000,'',function(){ window.location.replace("/login");})
}
}
})
}
else{
document.getElementById("auto_usuario").style.visibility = "hidden", auto_usuario.innerHTML = "";
$("#modal-search").css("height","unset");
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="buscadora" autofocus <?php if ($this->uri->segment(1) != null): ?> readonly <?php endif ?> class="input_box" name="tel_or_ced" onkeyup="autocomplete_usuario_debounced();">
when i put the autocomplete_usuario in the onkeyup in the input works fine but when i put autocomplete_usuario_debounced is not working
sorry for my bad english :D
You should define the
autocomplete_usuario_debouncedfunction this way: