title: Using Basic AJAX calls within Magento
body: <p>I'm writing a module to carry out a simple Ajax call in Magento, but I'm unable to get it work thus far - I feel like I'm missing a vital component somewhere. These are the files I currently have:</p>
  
  <p><strong>Creare/Groupedajax/controllers/AjaxController.php:</strong></p>
  
  <pre><code>class Creare_Groupedajax_AjaxController extends Mage_Core_Controller_Front_Action {
  
      public function indexAction() {
          $this-&gt;loadLayout();
          $this-&gt;renderLayout();
      }
  }
  </code></pre>
  
  <p><strong>Creare/Groupedajax/etc/config.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;config&gt;
    &lt;modules&gt;
      &lt;Creare_Groupedajax&gt;
        &lt;version&gt;0.1.0&lt;/version&gt;
      &lt;/Creare_Groupedajax&gt;
    &lt;/modules&gt;
    &lt;frontend&gt;
      &lt;routers&gt;
        &lt;groupedajax&gt;
          &lt;use&gt;standard&lt;/use&gt;
          &lt;args&gt;
            &lt;module&gt;Creare_Groupedajax&lt;/module&gt;
            &lt;frontName&gt;groupedajax&lt;/frontName&gt;
          &lt;/args&gt;
        &lt;/groupedajax&gt;
      &lt;/routers&gt;
      &lt;layout&gt;
        &lt;updates&gt;
          &lt;groupedajax&gt;
            &lt;file&gt;groupedajax.xml&lt;/file&gt;
          &lt;/groupedajax&gt;
        &lt;/updates&gt;
      &lt;/layout&gt;
    &lt;/frontend&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p><strong>My Ajax Call:</strong></p>
  
  <pre><code>$j.post("groupedajax/ajax/index", { size: $j(this).val()}, function(data) {
          $j('#results').html(data);
      });
  </code></pre>
  
  <p><strong>layout/groupedajax.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;layout version="1.0"&gt;
    &lt;groupedajax_ajax_index&gt;
      &lt;block type="groupedajax/groupedajax" name="root" output="toHtml" template="groupedajax/groupedajax.phtml" /&gt;
    &lt;/groupedajax_ajax_index&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>My .phtml file simply has 'test' in it at the moment. I just need my results div to return the 'test' value. I just want to know if all the bits are in place for this to work?</p>
  
  <p>This is the tutorial I have followed: <a href="http://www.atwix.com/magento/ajax-requests-in-magento/">http://www.atwix.com/magento/ajax-requests-in-magento/</a></p>
  
  <p><strong>======================== SOLVED ========================</strong></p>
  
  <p>I just needed a forward slash at the beginning of my url:</p>
  
  <pre><code>$j.ajax({
          url: "/groupedajax/ajax/index",
          type: "POST",
          data: "size="+$j(this).val(),
          success: function(data) {
          $j('#results').html(data);
          }
      });
  </code></pre>