Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delay .trigger('click') with overlay from jquery tools

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?

like image 380
Boris Goryachev Avatar asked Dec 10 '10 23:12

Boris Goryachev


2 Answers

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.

like image 92
David Tang Avatar answered Nov 03 '22 01:11

David Tang


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');                       
                    }
                }
        }); 
like image 43
TelegramSam Avatar answered Nov 03 '22 01:11

TelegramSam