Hello everybody,

im currently stuck with this problem.

I want to call a AJAX page via js (Example)

       setInterval(function () {
          $.ajax({
            type: 'get',
            url: settings['basePath'] + 'ajax/drupalcall/notification/',
            success: function (data) {            
            }
          });
          
        }, 5000);

The function page function looks like this.
The problem is that the AJAX commands are called but have no effect at all.

<?php
function drupalcom_display_incoming_call($call) {
  $commands = array();

  $commands[] = ajax_command_replace('#callarea', theme('drupalcom_incomming_call', array('cid' => $call->cid, 'calller' => $call->caller, 'callling' => $call->calling)));

  ajax_deliver(array('#type' => 'ajax', '#commands' => $commands));
}
?>

So my Question is now how i call a ajax page via js so I can use ajax_command.

Thanks for your time and help.

Timo Vogt

Comments

jaypan’s picture

Ajax commands will not work in a straight ajax call.

Contact me to contract me for D7 -> D10/11 migrations.

timo vogt’s picture

Is there another solution ?

I'm want to execute this ajax on a timer.

timo vogt’s picture

Workaround:
I created this link within my page

<a id="notification" class="use-ajax" href="ajax/drupalcall/notification/nojs">Call notification</a>

Then in my JavaScript I used the setInterval to click this link.

setInterval(function() {
  document.getElementById('notification').click();
}, 5000);

Just set the display to none so no one sees this link.