I am using Jquery tools, overlay effect and want to close it, if JSON response is OK, but i want to do it with a delay.
$.ajax({
//bla bla
success: function(data){
var obj = jQuery.parseJSON(data);
if (obj.status=='OK')
{
$('#status').text('bla bla');
jQuery('.close').trigger('click');
}
else
{
$('#status').text('bla bla');
}
}
});
so this - jQuery('.close').trigger('click'); must be executed after some time. Any ideas?
setTimeout()
is a native JavaScript function designed for this purpose.
setTimeout(function () {
jQuery('.close').trigger('click');
}, 1000);
The last number there is the delay time in milliseconds.
use setTimeout:
delay here is 1 second (1000 ms)
$.ajax({
//bla bla
success: function(data){
var obj = jQuery.parseJSON(data);
if (obj.status =='OK')
{
$('#status').text('bla bla');
setTimeout(function(){jQuery('.close').trigger('click');},1000);
}
else
{
$('#status').text('bla bla');
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With