ASD
ASD

Reputation: 4967

how to pass js variable in the ajax link function

How to pass the studentID in the URL? Since its js variable am getting error or its passed as string.

<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>

Upvotes: 1

Views: 1280

Answers (1)

GBD
GBD

Reputation: 15981

Try this way:

<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>

Upvotes: 2

Related Questions