Trigger and Event from within jQuery

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

Answers


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?


Need Your Help

Eclipse standard warning/error overlay icons

eclipse eclipse-plugin icons

I'm writing an Eclipse plug-in... In my custom label decorator, I want to overlay a warning icon, and I'd like to use the standard one used by eclipse (the little yellow triangle). How can I get an...

Return JSON from Web Service 4.0

iphone asp.net wcf web-services

I want return JSON from Web Service 4.0. I am creating an application for IPhone.