1

My controller is

public function init()
{
    /* Initialize action controller here */
    $ajaxContext = $this->_helper->getHelper('AjaxContext');
    $ajaxContext->addActionContext('get-ajax-content', 'html')
                ->initContext();
}

public function indexAction()
{
    // action body
    $form = new Zend_Form_Element_Select('menu');
    $parent_array=range('1','9');
        $form->addMultiOptions(array($parent_array));
        $this->view->form = $form;
}

for this form element, i am calling the ajax function,

<script type="text/javascript">

  $(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');
            }
        });
    });
 </script>

and the get-data action is following

public function getDataAction()
{
    // action body
    $this->view->message = 'This is an ajax message!';
    $params = array(    'host'      =>'localhost',
                        'username'  =>'root',
                        'password'  =>'',
                        'dbname'    =>'cms'
                       );
    $DB = new Zend_Db_Adapter_Pdo_Mysql($params);
    $section_id=$this->getRequest()->getPost('val');
    $menu_order='SELECT * FROM `cms_content_mst` WHERE section_id='.$section_id;
    $menu_order=$DB->fetchAll($menu_order);
    $newContent='<select id="sortorder" name="sortorder">';
    if(!empty($section_id) || $section_id != 0){
        if (empty($menu_order)) {
                    $newContent.='<option value="1" selected="selected">1</option>';
        }
        else
        {

        for ($i=1; $i <= count($menu_order) ; $i++) { 

                  $newContent.='<option value="'.$i.'"';
                  if($i==count($menu_order))
                  { $newContent.=' selected'; }
                  $newContent.='>'.$i.'</option>';

            }

        }
      }
      $newContent.='</select>';

    $this->view->new = $newContent;

}

i have fully worked jquery . i have .get function but on calling .ajax its is not working i am newbee to zend plz, help

1

1 Answer 1

0

Please! Check in console if you are able to load page.

 $.ajax({
            type: "POST",
            url: "get-data",
            data: "val="+$(this).val(),
            success: function(result){
                $("#div_sortorder").html(result);
            }

I think you have given wrong url.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.