0

I have struts2 jquery grid where on click of a row I am calling a jQuery function for performating a struts2 action. My code is running fine.

I want to perform my jQuery function after delay of a few seconds. How can I do this?

  <script type="text/javascript"> 
 //assume this code is working fine on rowselect from my jquery grid, New Updation in it is "i want to execute or load the url  after few seconds"
     $(function(){
            $.subscribe('rowselect', function(event,data) {
                var param = (event.originalEvent.id);  
                $("#myAdvanceDivBoxx").load('<s:url action='InsertbooksToSession' namespace='/admin/setups/secure/jspHomepage/bookstransaction'/>'+"?bid="+event.originalEvent.id);  
            });  
     }); 
</script>

What i tried is the below code but am unable to get the output which i am looking for:

 <script type="text/javascript">  
 $(function(){
        $.subscribe('rowselect', function(event,data) {
            var param = (event.originalEvent.id);  
            $("#myAdvanceDivBoxx").load('<s:url action='InsertbooksToSession' namespace='/admin/setups/secure/jspHomepage/bookstransaction'/>'+"?bid="+event.originalEvent.id);  
        }).delay(9000);  
 }); 
</script>
KatieK
  • 13,586
  • 17
  • 76
  • 90
james Bond
  • 11
  • 3

2 Answers2

0

delay postpones functions chained after it.

http://api.jquery.com/delay/

you just need a tried and true setTimeout.

https://developer.mozilla.org/en-US/docs/DOM/window.setTimeout

Heidtmare
  • 21
  • 7
0

only use delay for some animation/effects like:

$("div.first").slideUp(300).delay(800).fadeIn(400);

jQuery Delay

--

this should do the work, just use the setTimeout (docs) and see if helps you.

$.subscribe('rowselect', function(event,data) {
     var param = (event.originalEvent.id);  
     setTimeout(function(){
          $("#myAdvanceDivBoxx").load('<s:url action='InsertbooksToSession' namespace='/admin/setups/secure/jspHomepage/bookstransaction'/>'+"?bid="+event.originalEvent.id);  
     }, 9000);
 });
Ricardo Binns
  • 3,228
  • 6
  • 44
  • 71