jQuery function is not found by ajax.js

3 replies [Last post]
ajeancharles3
Offline
Last seen: 4 years 47 weeks ago
Joined: 2011-09-12

I am having trouble getting my jQuery function to be called by ajax.js

I have in my module the code call back code

...
$commands[] = ajax_command_invoke(NULL, 'initEventsAgain', array());
return array('#type' => 'ajax', '#commands' => $commands);
}

Which works fine (I can bring in new images) expect for the last part here, it cannot find the function "initEventsAgain" which is "inlined" in the web page, defined as follows,

(function($) {
  $.fn.initEventsAgain = function(){...}
})(jQuery);

Also, I tried not to enclose it into a jQuery namespace

 initEventsAgain = function(){...} // Removing the jQuery wrapper.

That does not work either, the ajax.js code cannot find the function. Is the function being loaded too late?.

Now I am leaning towards "Drupal.Behaviors". It seems promising.

Chris Shattuck
Offline
Last seen: 3 weeks 6 days ago
Joined: 2009-08-16
Hey there, I know it's been a

Hey there,

I know it's been a while since you asked, but if it's still a question, I'd like to know what the 'initEventsAgain' function should do. From it's name, it sounds like exactly what Drupal behaviors are meant to do, that is to run jQuery on new HTML on the page that needs behaviors attached to them.

Just in case, here's the video on using behaviors:

Cheers!
Chris

ajeancharles3
Offline
Last seen: 4 years 47 weeks ago
Joined: 2011-09-12
Hey there, I know it's been a

Thanks, i have it working, after playing the video a few dozen times.

Chris Shattuck
Offline
Last seen: 3 weeks 6 days ago
Joined: 2009-08-16
Ha! It took me a while to

Ha! It took me a while to wrap my mind around behaviors as well. I'm glad to hear you got it working.

Cheers!
Chris

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.