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 1.9.0.1.
After creating app/code/local/MichaelHarper/Upseller/controllers/AjaxController.php:
<?php
// Filename app/code/local/MichaelHarper/Upseller/controllers/AjaxController.php
class MichaelHarper_Upseller_AjaxController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
And app/code/local/MichaelHarper/Upseller/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<MichaelHarper_Upseller>
<version>0.1.0</version>
</MichaelHarper_Upseller>
</modules>
<frontend>
<global>
<blocks>
<upseller>
<class>MichaelHarper_Upseller_Block</class>
</upseller>
</blocks>
</global>
<routers>
<upseller>
<use>standard</use>
<args>
<module>MichaelHarper_Upseller</module>
<frontName>upseller</frontName>
</args>
</upseller>
</routers>
<layout>
<updates>
<upseller>
<file>ajaxlayout.xml</file>
</upseller>
</updates>
</layout>
</frontend>
</config>
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:
<upseller_ajax_index>
<reference name="content">
<block type="upseller/ajaxblock" name="root" template="upseller/default.phtml" />
</reference>
</upseller_ajax_index>
And finally my template file app/design/frontend/mytheme/default/template/upseller/default.phtml:
<?php
// 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:
xmlhttp.open("GET","upseller/ajax/index/someval/"+value,true);
-or-
jQuery.post(“upseller/ajax/index”, {someval: value}, function(data){...});
But testing them in the console renders errors.