Followed this tutorial: http://www.atwix.com/magento/ajax-requests-in-magento/

Though dated, people seem to be using it just fine. I'm using Magento CE

After creating app/code/local/MichaelHarper/Upseller/controllers/AjaxController.php:


// Filename app/code/local/MichaelHarper/Upseller/controllers/AjaxController.php

class MichaelHarper_Upseller_AjaxController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {

And app/code/local/MichaelHarper/Upseller/etc/config.xml:

<?xml version="1.0"?>


I'm able to go to my local site with controller namespace without error and it loads my theme's header and footer (blank body): http://localstore.dev/upseller/ajax/index

I then create app/design/frontend/mytheme/default/layout/ajaxlayout.xml:

    <reference name="content">
        <block type="upseller/ajaxblock" name="root" template="upseller/default.phtml" />

And finally my template file app/design/frontend/mytheme/default/template/upseller/default.phtml:

// app/design/frontend/mytheme/default/template/upseller/default.phtml
echo "Hello World";

Not getting anything when I load my site URL with namespace - still empty body. Any idea what I'm doing wrong? Also, once I can get my Hello World working I have these two provided methods for calling this AJAX controller:



jQuery.post(“upseller/ajax/index”, {someval: value}, function(data){...});

But testing them in the console renders errors.

  • where your block class?] – Amit Bera Sep 15 '14 at 15:58
  • Just added it into the config.xml file. Wasn't detailed in the tutorial. Also, the post keeps dropping the last two lines of my config.xml file where are: </frontend> </config> – sparecycle Sep 15 '14 at 16:11
  • What changes should I make to the ajaxlayout.xml file now that I've defined a block class? – sparecycle Sep 15 '14 at 16:12
  • block referece name is missing .it shoul <upseller_ajax_index> <reference name="content"> <block type="upseller/ajaxblock" name="root" template="upseller/default.phtml" /> </reference> </upseller_ajax_index> – Amit Bera Sep 15 '14 at 16:16
  • Thank you. Added. Refreshed but still nothing in the body. Is there another way to test/debug this? – sparecycle Sep 15 '14 at 16:22

The name of the layout update handle is created from the node name, in your case upseller, therefore I would try upseller_ajax_index

| improve this answer | |
  • Thanks for the fast response. Changed it to <block type="upseller/ajaxblock" name="root" template="upseller/default.phtml" /> </upseller_ajax_index> but still rendering blank page. – sparecycle Sep 15 '14 at 15:57
  • You should check app/code/core/Mage/Core/Controller/Varien/Action.php:289 which is the correct layout handle. If the handle is correct, check whether your block is loaded, t hen check the template – Fabian Blechschmidt Sep 15 '14 at 16:32

try by adding output attribute:

   <block type="upseller/ajaxblock" name="root" output="toHtml"  template="upseller/default.phtml" />
| improve this answer | |
  • Still blank. I turned on template hints but it doesn't reveal anything. What would be the correct parent path for "upseller/default.phtml"? Maybe I'm not pointing at the right directory. – sparecycle Sep 15 '14 at 17:51
  • 1
    is your module active? – MTM Sep 15 '14 at 18:32
  • Set to true. Good thing to check though. – sparecycle Sep 15 '14 at 18:34
  • do u still get the blank page? – MTM Sep 15 '14 at 18:36
  • Yes, sorry. It was set to true. I'm considering closing this question. Maybe there is something wrong with my install or a conflict that isn't obvious. – sparecycle Sep 15 '14 at 18:41

If you aim is to simply show your block on the ajax request and no other content such as header and footer then your layout.xml should be as follows.

    <block type="upseller/ajaxblock" name="root" output="toHtml" template="upseller/default.phtml" />

The key part there is the output="toHtml" which will actually get your block to show.

A great example of ajax work with layout is the one page checkout. I would suggest looking into the file app/design/frontend/base/default/layout/checkout.xml for any more information.

| improve this answer | |


   <reference name="content">
     <block type="upseller/ajaxblock" name="upseller.ajaxblock" template="upseller/default.phtml" />

Please be more consistence with your module and file name

| improve this answer | |
  • Still blank. I turned on template hints but it doesn't reveal anything. What would be the correct parent path for "upseller/default.phtml"? Maybe I'm not pointing at the right file? – sparecycle Sep 15 '14 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.