views:

69

answers:

1

I am looking at the possibility for an AutoCheck style jQuery HTML application that every 5 second it goes off the a DB and checks some data.

That is the easy part, which I can do.

Now what I would like is to have an AutoCheck time going, something like

var t = setTimeout("autocheck()", 5000);

So every 5 seconds it is triggered, and I would like it to raise an event.

The reason for this is so on other pages which include this feature can monitor that event and if raised do a task, the task the new page will do I don't care, just as long as the AutoCheck event is raised and the task is performed.

Any additional HTML / jQuery code with the page may also require to use the AutoCheck to perform another action based on the event.

So in short I need an AutoCheck to raise an event and for multiple listeners to trigger a process when that event is called

+1  A: 

Using what you've got...

Ajax calls already raise events. Why not use one of those? For instance, you could always bind logic to:

$.ajaxStart(function(){
  $(".msg").html("New Request Started.");
});

http://api.jquery.com/category/ajax/global-ajax-event-handlers/

Adding what you need...

If you find the present ajax events to be insufficient, you can create completely new events. I would suggest taking a look at the following question: How to dynamically register to jquery custom events?

Jonathan Sampson
Yes the link provided works a treat, I'm using $.ajaxStart(function() { $.event.trigger('customAjaxStart');});Many thanks
Coppermill