2012-12-24 39 views
1

如何在URL中傳遞studentID?由於它的js變量正在收到錯誤或作爲字符串傳遞。如何在ajax鏈接函數中傳遞js變量

<script>  
    function updateCallhistory(studentID) 
    { 
     <?php 
      echo CHtml::ajax(array(
      'url'=> Yii::app()->createUrl("siteiq/UpdateStudentForm", array("ClassID" => $ClassID)),   
      'data'=> "js:$(this).serialize()", 
      'type'=>'post', 
      'dataType'=>'json', 
      'success'=>"function(data) 
      { 
      if (data.status == 'failure') 
      { 
       $('#dialogStudentForm div.divForForm').html(data.div); 
        // Here is the trick: on submit-> once again this function! 
       $('#dialogStudentForm div.divForForm form').submit(updateCallhistory); 
      } 
      else 
      { 
       $('#dialogStudentForm div.divForForm').html(data.div); 
       setTimeout(\"$('#dialogStudentForm').dialog('close') \",1000); 
      } 

      } ", 
     ))?>; 
     return false; 
    } 
    </script> 
+0

功能updateCallhistory(studentID)這是一個PHP或js函數? – MJQ

+0

對不起,它的JS功能。我編輯了我的問題 – ASD

+0

這是哪個php變量在這個代碼中? – MJQ

回答

2

試試這個方法:

<script>  
    function updateCallhistory(studentID) 
    { 

     var url = '<?php echo Yii::app()->createUrl("siteiq/UpdateStudentForm", array("ClassID" => $ClassID)); ?>' + '&studentID='+studentID; 
     <?php 
      echo CHtml::ajax(array(
      'url'=> 'js:url',   
      'data'=> "js:$(this).serialize()", 
      'type'=>'post', 
      'dataType'=>'json', 
      'success'=>"function(data) 
      { 
      if (data.status == 'failure') 
      { 
       $('#dialogStudentForm div.divForForm').html(data.div); 
        // Here is the trick: on submit-> once again this function! 
       $('#dialogStudentForm div.divForForm form').submit(updateCallhistory); 
      } 
      else 
      { 
       $('#dialogStudentForm div.divForForm').html(data.div); 
       setTimeout(\"$('#dialogStudentForm').dialog('close') \",1000); 
      } 

      } ", 
     ))?>; 
     return false; 
    } 
    </script> 
+0

完美。它的工作很好。謝謝。 – ASD