0

I am wondering if it is possible to stack two ajax_command_replace commands. In other words, to have code that looks like this:

<br>
$commands = array();<br>
$commands[] = ajax_command_replace($selector1, $data1);<br>
$commands[] = ajax_command_replace($selector2, $data2);<br>
ajax_deliver(array('#type' => 'ajax', '#commands' => $commands);<br>

and then to expect both commands to run?

When I try this, the first command runs just fine, but the second command does not. I have reversed the order of the two commands, and sure enough, the (new) first command now runs, but the (new) second command does not. I have also looked at the page after the ajax_deliver has run, and the first command did not destroy the html on the page, so the second command's selector is still there. I have also added a dummy ajax_command_alert just to be sure that I can run multiple commands, and that works as well.

An added comment: If you use ajax_command_replace, you lose the tags on the selector you have chosen. Two options to get around this are (1) Use ajax_command_html (which retains the outer tag) or (2) include the outer tag information in the html for the ajax_command_replace.I still, however, cannot stack two ajax_command_replace or ajax_command_html commands.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.