top of page

Drupal – Run AJAX command after success of another JS command.

  • Writer: Qasim Zee
    Qasim Zee
  • Jun 27, 2015
  • 1 min read

With ajax_command_invoke, I was getting error: Uncaught TypeError: Cannot read property ‘apply’ of undefined — ajax.js

Terrible!

After banging my head for like 4 hours with ajax_command_invoke, I am finally able to do it. Here is an example code.

PHP

function drupal_custom_ajax_test_ajax_call() { drupal_set_message('AJAX call received'); $commands = array(); $commands[] = array('command' => 'myJSFunction'); $commands[] = ajax_command_after('#main-content', theme('status_messages')); $page = array( '#type' => 'ajax', '#commands' => $commands, ); ajax_deliver($page); }

1

2

3

4

5

6

7

8

9

10

11

12

function

drupal_custom_ajax_test_ajax_call

(

)

{

drupal_set_message

(

'AJAX call received'

)

;

$commands

=

array

(

)

;

$commands

[

]

=

array

(

'command'

=

>

'myJSFunction'

)

;

$commands

[

]

=

ajax_command_after

(

'#main-content'

,

theme

(

'status_messages'

)

)

;

$page

=

array

(

'#type'

=

>

'ajax'

,

'#commands'

=

>

$commands

,

)

;

ajax_deliver

(

$page

)

;

}

Here is the full code.

Recent Posts

See All
Centos, Varnish, NGINX, Drupal

As an experiment this week I decided to change the web server of a site to NGINX, the existing web server was Apache.

 
 
 

תגובות


bottom of page