gpt4 book ai didi

php - 如何在ajax链接函数中传递js变量

转载 作者:行者123 更新时间:2023-11-30 18:13:21 26 4
gpt4 key购买 nike

如何在URL中传递studentID?由于其 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>

最佳答案

试试这个方法:

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

关于php - 如何在ajax链接函数中传递js变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14018299/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com