Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to "print" a theme during AJAX request (Drupal)
    primarykey
    data
    text
    <p>When users click on a button (with <code>id</code> graph), I'd like to fill the default Drupal content <code>div</code> (<code>&lt;div class="content"&gt;</code>) with a graphael instance. </p> <p>The JavaScript:</p> <pre><code>jQuery(document).ready(function($) { $('#toggle #graph').click(function() { $.ajax({ url: "http://www.mysite.com/?q=publications/callback", type: 'POST', data: { 'format' : 'graph' }, success: function(response) { $('div#content div.content').html(response); } }); }); }); </code></pre> <p>The PHP:</p> <pre><code>$items['publications/callback'] = array( 'type' =&gt; MENU_CALLBACK, 'title' =&gt; 'All Publications Callback', 'page callback' =&gt; '_process_publications', 'page arguments' =&gt; array(t('journal')), 'access callback' =&gt; TRUE, ); </code></pre> <p>which leads to the page callback: (I'm concerned with the <code>if</code> code block)</p> <pre><code>function _process_publications($venue) { if( isset($_POST['format']) &amp;&amp; $_POST['format'] == "graph" ){ _make_bar_chart($venue); } elseif( isset($_POST['format']) &amp;&amp; $_POST['format'] == "list" ) { _make_list($venue); } else{ return("&lt;p&gt;blah&lt;/p&gt;"); } } </code></pre> <p>and finally the function called within the callback function:</p> <pre><code>function _make_bar_chart($venue) { // get active database connection $mysql = Database::getConnection(); // if connection is successful, proceed if($mysql){ // do stuff $graphael = array( 'method' =&gt; 'bar', 'values' =&gt; $ycoordinates, 'params' =&gt; array( 'colors' =&gt; $colors, 'font' =&gt; '10px Arial, sans-serif', 'opts' =&gt; array( 'gutter' =&gt; '20%', 'type' =&gt; 'square', ), 'label' =&gt; array( 'values' =&gt; $xcoordinates, 'isBottom' =&gt; true, ), ), 'extend' =&gt; array( 'label' =&gt; array( 'values' =&gt; $ycoordinates, 'params' =&gt; array('attrText' =&gt; array( 'fill' =&gt; '#aaa', 'font' =&gt; '10px Arial, sans-serif', )), ), ), ); return theme('graphael', $graphael); } // else, connection was unsuccessful else{ print("&lt;p&gt;bad connection&lt;/p&gt;"); } } </code></pre> <p><strong>THE PROBLEM:</strong> returning a theme doesn't really send anything back to the AJAX request (unlike <code>print</code> statements). I tried to print the theme, but that produces a white screen of death. How would I generate the graph without printing something?</p>
    singulars
    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.
 

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