Stopping a loaded component

36 views
Skip to first unread message

Francisco Ribeiro

unread,
Sep 14, 2017, 10:35:06 PM9/14/17
to web2py-users
Hi all,

I have a monitoring component in which my app continuously grabs data from the database through a controller which is triggered by a javascript call as follows:

$.web2py.component("{{=URL('controller', 'my_function.load')}}", "my_target", timeout=2000, times='Infinity');

As you can see, this component is calling my controller every 2s for an infinite number of times and it works well.

Now, I would like to add an option to allow the user to arbitrarily stop this monitoring component but I could not find a way to trap and stop the JS call above (nor its reload_check) once the page and the component are loaded. Any ideas?

Thank you
Kind regards,
Francisco

Francisco Ribeiro

unread,
Sep 15, 2017, 7:04:58 PM9/15/17
to web2py-users
Found a solution for this which is to add the 'w2p_component_stop' class onto the div, as follows:

  $('#my_target').addClass('w2p_component_stop');
  $
('#my_target').html('');

this will break the infinite loop set by the call in my original post and then will hide the content left from the last iteration of the loop.

Francisco
Reply all
Reply to author
Forward
0 new messages