I have the following function in my code. Here’s a simplified version:
$.ajax({
url: $form.attr('action'),
dataType: 'json',
type: 'POST',
data: $form.serializeArray(),
success: function (json, textStatus, XMLHttpRequest) {
// delay here
alert("hello");
}
Is there some way that I can introduce a delay. For example a delay of 5 seconds into the above code?
Note that I need to replace the words // delay here with something that can give a delay if possible.
You can use
setTimeout()with an anonymous function:This will run the code within that function after a 5-second delay.