Hi Folks,
I have a tiny AJAX example and it works -- in fact it works too well. On the first click, it does what it is supposed to do -- insert a DOM node with text after the <A> node with id=ajax-enabled.. On the second click is does it TWICE and I can see two throbbers run. On the third click, you guessed it, FOUR throbbers. Is there some context that I need to clear after the AJAX call or some object I need to re-use to prevent this?
Also, as I investigate the DOM with the browser inspector, I can't find where all the event handlers are attached. When I look in the naive places, I see references to jQuery, but I believe that jQuery is dispatching to something somewhere and I'd like to know where that somewhere is. I should be able to find it.
Thanks for the help,
Chris.
Drupal behaviors gets called whenever something is called on AJAX, so you need to make sure you're doing any binding or DOM manipulation only once. Check out something like autocomplete.js in Drupal's misc folder. In Drupal 6 it adds a selector of :not(.autocomplete-processed), then adds that class to the element in the each loop so it doesn't do things that should run once on every AHAH/AJAX call. Drupal 7 uses the jQuery .once library to make it a little simpler.
Jamie Holly http://hollyit.net
On 10/23/2013 5:41 PM, Chris Miller wrote:
Hi Folks,
I have a tiny AJAX example and it works -- in fact it works too well. On the first click, it does what it is supposed to do -- insert a DOM node with text after the <A> node with id=ajax-enabled.. On the second click is does it TWICE and I can see two throbbers run. On the third click, you guessed it, FOUR throbbers. Is there some context that I need to clear after the AJAX call or some object I need to re-use to prevent this?
Also, as I investigate the DOM with the browser inspector, I can't find where all the event handlers are attached. When I look in the naive places, I see references to jQuery, but I believe that jQuery is dispatching to something somewhere and I'd like to know where that somewhere is. I should be able to find it.
Thanks for the help,
Chris.