title: Submit form data using Ajax in Yii1
body: <p>I tried to submit a form using ajax. Below is my code:</p>
  
  <p>controller code:</p>
  
  <pre><code>public function actionIndex($complaint, $work)
      {
          ...
          $this-&gt;render('index',array(
              'model'         =&gt;  $model,
              'work_order'    =&gt;  $work_order,
              'work'          =&gt;  $work,
              'complaint'     =&gt;  $complaint,
              'work_complaint'=&gt;  $work_complaint
          ));
      }
  </code></pre>
  
  <p>ajax action</p>
  
  <pre><code>public function actionCreate($complaint,$work)
      {
      ...
  
          $this-&gt;renderPartial('create',array(
              'model'             =&gt;  $model,
              'complaint'         =&gt;  $complaint,
              'work'              =&gt;  $work,
              'work_complaint'    =&gt;  $work_complaint,
              'work_order'        =&gt;  $work_order,
              'man_hour'          =&gt;  $man_hour,
              'jobs'              =&gt;  $jobs,
          ));
      }
  </code></pre>
  
  <p>my views</p>
  
  <p>Create.php</p>
  
  <pre><code>&lt;h1&gt;Add Job&lt;/h1&gt;
  
  &lt;?php $this-&gt;renderPartial('_form', array('model'           =&gt;  $model,
                                            'work_complaint'  =&gt;  $work_complaint,
                                            'work_order'      =&gt;  $work_order,        
                                            'man_hour'        =&gt;  $man_hour,      
                                            'jobs'            =&gt;  $jobs,
                                            'complaint'       =&gt; $complaint, 
                                            'work'            =&gt; $work
                          )); ?&gt;
  </code></pre>
  
  <p>my _form.php</p>
  
  <pre><code>&lt;div class="form"&gt;
  
  
  
  &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
              'id'=&gt;'post-form',
              'enableAjaxValidation'=&gt;false,
      )); ?&gt;
  ...
  
      &lt;div class="row buttons"&gt;
          &lt;div class="col-md-6 col-lg-6" &gt;
          &lt;?php echo CHtml::ajaxSubmitButton ("Post",
                  array('complaintJob/create','complaint'=&gt;$complaint,'work'=&gt;$work),
                              array('update' =&gt; '#post')); ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  
  &lt;/div&gt;&lt;!-- form --&gt;
  </code></pre>
  
  <p>my index.php</p>
  
  <pre><code>&lt;div id="post"&gt;
  
  &lt;?php 
          $man_hour       =   ManHourMaster::model()-&gt;findByPk(1);
          $jobs           =   Job::model()-&gt;with('job_category1')-&gt;findAll( "job_category1.is_separate = 0" );
          $this-&gt;renderPartial('create',array(
                      'model'             =&gt;  $model,
                      'complaint'         =&gt;  $complaint,
                      'work'              =&gt;  $work,
                      'work_complaint'    =&gt;  $work_complaint,
                      'work_order'        =&gt;  $work_order,
                      'man_hour'          =&gt;  $man_hour,
                      'jobs'              =&gt;  $jobs,
                  ));
  ?&gt;
  &lt;/div&gt;
  ...
  </code></pre>
  
  <p>so when i run this code i get the form, and when i submit it, i basically get  2 copies of the same view.</p>