Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Much thanks to <em>nevets</em> on the Drupal forums for the helpful hint: <a href="http://drupal.org/node/1664798#comment-6177944" rel="nofollow">http://drupal.org/node/1664798#comment-6177944</a></p> <p>If you want to use AJAX with Drupal, you are best off actually using Drupal-specific AJAX-related functions. In my theme's <code>page.tpl.php</code> file, I added the following to make the links which would call AJAX:</p> <pre><code>&lt;?php // drupal_add_library is invoked automatically when a form element has the // '#ajax' property, but since we are not rendering a form here, we have to // do it ourselves. drupal_add_library('system', 'drupal.ajax'); // The use-ajax class is special, so that the link will call without causing // a page reload. Note the /nojs portion of the path - if javascript is // enabled, this part will be stripped from the path before it is called. $link1 = l(t('Graph'), 'ajax_link_callback/graph/nojs/', array('attributes' =&gt; array('class' =&gt; array('use-ajax')))); $link2 = l(t('List'), 'ajax_link_callback/list/nojs/', array('attributes' =&gt; array('class' =&gt; array('use-ajax')))); $link3 = l(t('Create Alert'), 'ajax_link_callback/alert/nojs/', array('attributes' =&gt; array('class' =&gt; array('use-ajax')))); $output = "&lt;span&gt;$link1&lt;/span&gt;&lt;span&gt;$link2&lt;/span&gt;&lt;span&gt;$link3&lt;/span&gt;&lt;div id='myDiv'&gt;&lt;/div&gt;"; print $output; ?&gt; </code></pre> <p>When one of the links above is clicked, the callback function is called (e.g. ajax_link_callback/graph):</p> <pre><code>// A menu callback is required when using ajax outside of the Form API. $items['ajax_link_callback/graph'] = array( 'page callback' =&gt; 'ajax_link_response_graph', 'access callback' =&gt; 'user_access', 'access arguments' =&gt; array('access content'), 'type' =&gt; MENU_CALLBACK, ); </code></pre> <p>.. and the callback to which it refers:</p> <pre><code>function ajax_link_response_graph($type = 'ajax') { if ($type == 'ajax') { $output = _make_bar_chart('journal'); $commands = array(); // See ajax_example_advanced.inc for more details on the available commands // and how to use them. $commands[] = ajax_command_html('div#content div.content', $output); $page = array('#type' =&gt; 'ajax', '#commands' =&gt; $commands); ajax_deliver($page); } else { $output = t("This is some content delivered via a page load."); return $output; } } </code></pre> <p>This replaces any HTML within <code>&lt;div class="content"&gt;</code> with the <em>graphael</em> chart returned from _make_bar_chart above. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload