Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's what I learned when I was making my ZF/Ajax app. </p> <p><strong>For HTML Data:</strong></p> <p>You can use ActiionContext action helper (<a href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html" rel="nofollow">ZF Reference</a>). You can add an AJAX context to your actions. I use this in controller's init() function. </p> <pre><code>$ajaxContext = $this-&gt;_helper-&gt;getHelper('AjaxContext'); $ajaxContext-&gt;addActionContext('myaction', 'html')-&gt;initContext('html'); </code></pre> <p>What this does is, when calling myactionAction(), it will check if the request is made through an AJAX call. If it is, it disables the layout, and renders "myaction.<strong>ajax</strong>.phtml" rather than "myaction.phtml" as it would if it wasn't an AJAX call. This way, you can get a clean HTML output from an action without anything extra, you don't have to write a Request-Type checking code in each action. I found it generally easy work with. </p> <p>If the content you are loading carries additional javascript with it, don't forget to add it to your view and echo it as well. </p> <pre><code>$this-&gt;headScript()-&gt;appendFile("/js/list.js"); echo $this-&gt;headScript(); </code></pre> <p>That JavaScript then executes as it normally would. </p> <p><strong>For JSON Data</strong></p> <p>JSON Action Helper is very quick and easy to use in an action to return JSON data. </p> <pre><code>$r = "Success"; $this-&gt;_helper-&gt;json($r); </code></pre> <p>This also returns pure JSON and nothing else. </p> <p>I guess a little more specific question would help you get better answers. </p>
 

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