title: Using ajax in zend framework
body: <p>My controller is </p>
  
  <pre><code>public function init()
  {
      /* Initialize action controller here */
      $ajaxContext = $this-&gt;_helper-&gt;getHelper('AjaxContext');
      $ajaxContext-&gt;addActionContext('get-ajax-content', 'html')
                  -&gt;initContext();
  }
  
  public function indexAction()
  {
      // action body
      $form = new Zend_Form_Element_Select('menu');
      $parent_array=range('1','9');
          $form-&gt;addMultiOptions(array($parent_array));
          $this-&gt;view-&gt;form = $form;
  }
  </code></pre>
  
  <p>for this form element, i am calling the ajax function, </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
    $(document).ready(function(){
      $("#menu").change(function(){
          $.ajax({
              type: "POST",
              url: "get-data",
              data: "val="+$(this).val(),
              success: function(result){
                  $("#div_sortorder").html(result);
              },
              error: function(){
                  //console.log('error');
              },
              complete: function(){
                  //console.log('complete');
              }
          });
      });
   &lt;/script&gt;
  </code></pre>
  
  <p>and the  get-data action is following</p>
  
  <pre><code>public function getDataAction()
  {
      // action body
      $this-&gt;view-&gt;message = 'This is an ajax message!';
      $params = array(    'host'      =&gt;'localhost',
                          'username'  =&gt;'root',
                          'password'  =&gt;'',
                          'dbname'    =&gt;'cms'
                         );
      $DB = new Zend_Db_Adapter_Pdo_Mysql($params);
      $section_id=$this-&gt;getRequest()-&gt;getPost('val');
      $menu_order='SELECT * FROM `cms_content_mst` WHERE section_id='.$section_id;
      $menu_order=$DB-&gt;fetchAll($menu_order);
      $newContent='&lt;select id="sortorder" name="sortorder"&gt;';
      if(!empty($section_id) || $section_id != 0){
          if (empty($menu_order)) {
                      $newContent.='&lt;option value="1" selected="selected"&gt;1&lt;/option&gt;';
          }
          else
          {
  
          for ($i=1; $i &lt;= count($menu_order) ; $i++) { 
  
                    $newContent.='&lt;option value="'.$i.'"';
                    if($i==count($menu_order))
                    { $newContent.=' selected'; }
                    $newContent.='&gt;'.$i.'&lt;/option&gt;';
  
              }
  
          }
        }
        $newContent.='&lt;/select&gt;';
  
      $this-&gt;view-&gt;new = $newContent;
  
  }
  </code></pre>
  
  <p>i have fully worked jquery . i have .get function but on calling .ajax its is not working
  i am newbee to zend plz, help</p>