#StackBounty: #magento-1.9 #controllers #ajax My controller isn't loading the view via Ajax

Bounty: 50

Following on from a question I asked yesterday, I now need to get ajax working in my plugin. I’ve been following several tutorials but can’t seem to get it working:

I’ve set up my XML file that is correctly loading in the content on my product page:

<layout version="0.1.0">
        <reference name="content">
        <reference name="content">
            <block type="finance/finance" name="finance" as="finance" template="finance/init.phtml"/>
        <remove name="right"/>
        <remove name="left"/>
        <block type="finance/finance" name="finance_ajax" as="finance_ajax" template="finance/ajax.phtml" output="toHtml"/>

My AjaxController.php has been set up as follows:

<?php class Eden_Finance_AjaxController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {

    public function ajaxAction() {
        $isAjax = Mage::app()->getRequest()->isAjax();
        if ( $isAjax ) {
            $layout = $this->getLayout();
            $update = $layout->getUpdate();
            $update->load( 'finance_ajax_ajax' );
            $output = $layout->getOutput();
            $this->getResponse()->setHeader( 'Content-type', 'application/json' );
            $this->getResponse()->setBody( Mage::helper( 'core' )->jsonEncode( array( 'outputHtml' => $output ) ) );


and I’m using the following in my init.phtml to try and load the ajax content from ajax.phtml, but when logging data, all I get is {"outputHtml":""}:

    function getFinance() {
        var months = $j("select[name='finance']").val();
            beforeSend: function() {
            url: "getUrl('finance/ajax/ajax');?>",
            type: "POST",
            dataType: 'json',
            data: {
                id: getId();?>,
                months: months
            success: function (data) {
            complete: function(){
    $j(document).ready(function() {
        return false;
    $j("select[name='finance']").change(function() {
        return false;

No matter what I change, I can’t seem to get any output from the controller.

Here’s Git a repo to get a better idea of what’s going on. If you copy it all into a Magneto installation (but use your own view.phtml) you’ll see..

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.