2013-10-29 21 views
0

這裏是我的代碼爲ajaxsubmitbutton如何使用AjaxSubmitButtom在警予

<?php echo CHtml::ajaxLink('Assign',CController::createUrl('StudentsGuardian/Create',array('$guardian_id'=>$id,'$student_id'=>'js:studentid'),array('dataType'=>'html', 'complete'=>'js:alert("hurray")'))); ?> 

但這提交按鈕不起作用。我需要從這個ajax按鈕調用控制器的動作,但無法做到這一點。這裏是我的控制器創建行動

public function actionCreate($guardian_id, $student_id) 
    { 

      CVarDumper::Dump($guardian_id,100,true); 
      CVarDumper::Dump($student_id,100,true); 
      die(); 
     $model=new StudentsGuardian; 

       $model->guardian_id = $guardian_id; 
       $model->student_id = $student_id; 
     // Uncomment the following line if AJAX validation is needed 
     // $this->performAjaxValidation($model); 

    } 

我已經把VarDumper看值,但是當推只是使得它所屬的觀點,這是從來沒有表現出BCZ Ajaxbutton。它什麼都不做。
我是yii的新手,所以請幫助我,指點我正確的方式。
更新:
這裏是我的javascript代碼中srudentId設置

<script type="text/javascript"> 

     var studentid; 
     $("#dropdownId").change(function(){ 
      studentid= $('#dropdownId :selected').val(); 

     }); 

    </script> 

當droplist改變那麼這studentid設置。

回答

0

這行不通,因爲studentid沒有設置, ,它不是意味着要使用這種方式,它總是會在網頁加載時爲空,所以始終是空

也ajaxSubmitButton通過發送相關的表格我想GET方法,您需要從GET

+0

事實上,我需要在頁面加載該值。當dropDownList被改變時,Javascript被調用,然後它的值被設置。 –

+0

你正在使用錯誤的句法與那 – tinybyte

+0

哪個語法錯誤? javascript變量調用? –

0

更改數據類型的方法讓您的參數信息類型

<?php echo CHtml::ajaxLink('Assign', 
    CController::createUrl('StudentsGuardian/Create'), 
    array('type' => 'POST', 
     'data' => array('guardian_id' => $id, 'student_id'=> 'js:studentid'), 
     'complete' => 'js:alert("hurray")' 
    ) 
); ?> 

這是什麼「JS:studentid」?

控制器:

public function actionCreate($guardian_id, $student_id) 
{ 
    $guardian_id = isset($_POST['guardian_id'])? $_POST['guardian_id'] : $guardian_id; 
    $student_id = isset($_POST['student_id'])? $_POST['student_id'] : $student_id; 

    CVarDumper::Dump($guardian_id,100,true); 
    CVarDumper::Dump($student_id,100,true); 
    die(); 
    $model=new StudentsGuardian; 

    $model->guardian_id = $guardian_id; 
    $model->student_id = $student_id; 
    // Uncomment the following line if AJAX validation is needed 
    // $this->performAjaxValidation($model); 

}