-2

I'm trying to put a delay in front of an AJAX call.

var delay = 2000;

$("#c_name").on("keyup", function() {
  var entered = $(this).val();
  if (entered.length > 1) { 
    setTimeout(dosearch(entered), delay) 
    }
  });

Fo some reason I can't seem to get setTimeout to take hold. It's performing the dosearch() function instantly.

How can I get this to delay properly? Yes JQuery 3.3.1 is loaded up top.

Rich_F
  • 1,830
  • 3
  • 24
  • 45

1 Answers1

-1

Answer: Both of these work:

setTimeout(() => dosearch(entered), delay) 

setTimeout( function() { dosearch(entered) }, delay) 
Rich_F
  • 1,830
  • 3
  • 24
  • 45