Thursday, June 28, 2012

jQuery - Multiple Subscriptions to a Topic

The other thing that caught me a couple of times this past month were multiple subscriptions to a topic when using subscribe. This was causing my AJAX action to be called multiple times. It turns out that if you do this:

$.subscribe('Whatever}', function(event,data) {...
in the page that you are returning using AJAX, the subscribe is saved. So the next time you make the same AJAX request and return with the page you will have another subscription to the topic.
What you need to do is specify the id of the tag like this this:

$('#TheID').subscribe('Whatever', function(event,data) {...

No comments:

Post a Comment

Thank you for commenting!