1

On my pages I have several different elements that are showing different representations of the underlying data. I have AJAX that will update the data through a PHP page, but I then want to trigger an update of all the different elements so they reflect the changes.

I'm thinking of binding the independent elements to a custom event "PageUpdate" so that if anything changes, a single event can be fired to update all elements.

I want to know if there is a way to automate this so that the custom event is always triggered when other events are triggered? Or would I have to put $.trigger("PageUpdate") in every other event I want to trigger "PageUpdate"? Additionally, can I filter out based on the events, when this is triggered? Not all events require a full page update.

The goal is to not have to go back and put .trigger() calls in the old code and to make it so we don't have to remember it for every event going forward.

CLo
  • 3,650
  • 3
  • 26
  • 44
  • can you just use setInterval() to poll the changes, and assess if a change has been made? – Mild Fuzz Mar 05 '12 at 13:44
  • I think you would have to override some event methods, do additionally add you custom event. But why do you want your PageUpdate event triggered on every other event ? – mas-designs Mar 05 '12 at 13:49
  • @MildFuzz The polling would require AJAX calls, and they won't be needed until the user actually does something. Also, we want to make the interface feel like it's responding to the user. – CLo Mar 05 '12 at 13:51
  • 1
    take a look at knockout.js...powerful databinding – charlietfl Mar 05 '12 at 13:52
  • @EvilP I'm not necessarily interested in having it triggered on every other event. But I'd rather have it triggered by all events and be able to filter, rather than having to add triggers to several different events on each page. If there isn't a better option. – CLo Mar 05 '12 at 13:52

1 Answers1

0

Refer to this page for how to bind an event handler to all events - All events example

Then you could probably call / trigger your custom event in that event handler. You'll also probably be able to filter on the event by looking at the e object passed to your event handler function.

Community
  • 1
  • 1
Ettiene Grobler
  • 535
  • 3
  • 15