1

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>
6
  • function updateCallhistory(studentID) Is this a php or a js function? Commented Dec 24, 2012 at 7:32
  • Sorry its JS function. I have edited my question Commented Dec 24, 2012 at 7:38
  • Which is php variable in this code??? Commented Dec 24, 2012 at 7:43
  • so... you're calling js function to call php code to echo js code? This doesn't sound right... Commented Dec 24, 2012 at 7:46
  • What do you mean by "it is passed as string"? If you want it in a URL, it will be always string, since URLs are texts. And what is problem with being string? PHP handles types very vague anyway. Commented Dec 24, 2012 at 7:46

1 Answer 1

2

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