[support] AJAX
Chris Miller
cjm at tryx.org
Thu Oct 24 22:02:28 UTC 2013
Hi Folks,
I have discovered why I am getting multiple events -- increasingly multiple events. In the following code, the "attach" method is called for each click and notice that this has the effect of attaching a new event handler for each event handler already attached.
And here's the mystery: My code differs by ONLY identifiers from the example I followed ( http://interactivejunky.com/tutorial-demos/ij-ajax-commands/trigger-page ) and the example works correctly which leaves unexplained why I have to add an unbind() call to avoid the multiple attach problem. I considered that it might be the version of jQuery, but I see the same problem with both 1.7 and 1.8, so at least as far as jQuery_update is concerned, it is not a jQuery issue. I don't know if it is a "behaviors" issue, because I still don't fully understand how "behaviors" works. Anybody have any insight into this question? (Attached is the complete (trivial) module for experimentation, should that be interesting.)
(function ($) {
Drupal.behaviors.modc = {
attach: function(context, settings) {
var $AJAXEnabled = $('#ajax-enabled');
$AJAXEnabled.unbind();
new Drupal.ajax('#ajax-enabled', $AJAXEnabled, {
url: $AJAXEnabled.attr('href'),
settings: {},
event: 'click tap'
});
}
}
})(jQuery);
Chris.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20131024/a64a98af/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ajax.zip
Type: application/zip
Size: 1523 bytes
Desc: not available
Url : http://lists.drupal.org/pipermail/support/attachments/20131024/a64a98af/attachment.zip
More information about the support
mailing list