我在对话框关闭功能上使用 ajax 调用时遇到了这个问题。
这是我的ajax调用函数:
function samplefunction(var1,var2){
$.ajax({
url: "controllerFunction?var1="+var1+"&var2="+var2,
type: 'POST',
dataType: 'json',
success: function(data)
{
$("#htmlmessage").html(data.message);
$("#htmlmsgdialog").dialog("open");
}
});
}
下面是对话框代码:
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'sampledialogboxname',
'options'=>array(
'title'=>'Sample Dialog Box I',
'autoOpen'=>false,
'modal'=>true,
'resizable'=>false,
'draggable'=>false,
'position'=>array("middle",30),
'width'=>650,
'show'=>'fade',
'hide'=>'fade',
'open' => 'js:function(event,ui){
//some code here
}',
**'close' => 'js:function(event,ui){
samplefunction("samplestring1","samplestring2");
window.location.href = "'.$sampleurl.'";
}',**
'buttons' => array
(
array('id' => 'firstback','text'=>'BACK',
'click'=> 'js:function(){
samplefunction("samplestring1","samplestring2");
$(this).dialog("close");
window.location.href = "'.$sampleurl.'";
}'),
array('id' => 'secondback','text'=>'BACK','click'=> 'js:function(){
//some code here
}'),
array('id' => 'thirdback','text'=>'BACK','click'=> 'js:function(){
//some code here
}'),
array('id' => 'fourthback','text'=>'BACK','click'=> 'js:function(){
//some code here
}'),
array('id' => 'firstnext','text'=>'NEXT','click'=> 'js:function(){
//some code here
}'),
array('id' => 'secondnext','text'=>'NEXT','click'=> 'js:function(){
//some code here
}'),
array('id' => 'thirdnext','text'=>'NEXT','click'=> 'js:function(){
//some code here
}'),
array('id' => 'save','text'=>'SAVE','click'=> 'js:function(){
//some code here
}')
),
),
));?>
这是控制器功能:
public function actionControllerFunction($var1, $var2)
{
var_dump($var1, $var2);
//Do Some Code here
$result['showdialog'] = true;
$result['message'] = "Sample Msg.";
echo json_encode($result);
exit;
}
我的问题是,即使在我进入控制器功能之前,ajax 调用也总是失败。我检查了我的参数,它还有要传递的适当字符串。我非常需要帮助。任何对我有帮助的评论都将受到高度赞赏。谢谢。(^__^)