title: Ajax In Magento
body: <p>I've been reading about ajax in magento and their is alot of talk about modules and controllers, so after managing to setup a custom module, controller and frontend router
  i'm now having problems, at the moment i just want my ajax call to return an category page and its products depending on what id/param is posted to the controller. I dont know alot about PHP so i looked around and came cross this </p>
  
  <h1>The Controller</h1>
  
  <p>
  
  <pre><code>public function indexAction() {
          $id = $this-&gt;getRequest()-&gt;getParam('id');
  
          if($id) {
              $_category = Mage::getModel('catalog/category')-&gt;load($id);
              $product = Mage::getModel('catalog/product');
  
              //load the category's products as a collection
              $_productCollection = $product-&gt;getCollection()
                  -&gt;addAttributeToSelect('*')
                  -&gt;addCategoryFilter($_category)
                  -&gt;load();
  
              // build an array for conversion
              $json_products = array();
              foreach ($_productCollection as $_product) {
                  $_product-&gt;getData();
                  $json_products[] = array(
                              'name' =&gt; ''.$helper-&gt;htmlEscape($_product-&gt;getName()).'',
                              'url' =&gt; ''.$_product-&gt;getProductUrl().'',
                              'description' =&gt; ''.nl2br($_product-&gt;getShortDescription()).'',
                              'price' =&gt; ''.$_product-&gt;getFormatedPrice().'');
              }
  
              $data = json_encode($items);
  
              echo $data;
          }
       $this-&gt;loadLayout(array('helloworld_index_index'));
       $this-&gt;renderLayout();
      }
  }
  </code></pre>
  
  <p>i know this is not exactly what i need but im having trouble coming to grips ajax in magento
  what i had in mind is that: </p>
  
  <ol>
  <li>in a ajax call i send the ID of the category to the controller</li>
  <li>the controller then arrays the products of the selected the category </li>
  <li>the array of products is sent/styled to the template file which is then sent back</li>
  </ol>
  
  <p>if anyone can please help me i would be truly greatful</p>
  
  <p>Thank you </p>