Php Ajax调用yii对话框关闭功能失败
我在使用ajax调用对话框关闭函数时遇到了这个问题 下面是我的ajax调用函数:Php Ajax调用yii对话框关闭功能失败,php,jquery,yii,jquery-dialog,zii-widgets,Php,Jquery,Yii,Jquery Dialog,Zii Widgets,我在使用ajax调用对话框关闭函数时遇到了这个问题 下面是我的ajax调用函数: function samplefunction(var1,var2){ $.ajax({ url: "controllerFunction?var1="+var1+"&var2="+var2, type: 'POST', dataType: 'json', success: function(data) {
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");
}
});
}
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;
}
以下是对话框代码:
<?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
}')
),
),
));?>
我的问题是,ajax调用总是在我进入控制器函数之前失败。
我检查了我的参数,它还具有要传递的适当字符串。
我急需帮助。非常感谢任何对我有帮助的评论。
谢谢(^ _^)我认为最好的办法是通过ajax函数修复正在访问的url: 在视图文件中
$sampleurl=Yii::app()->createUrl("controllerName/sampleFun");
$ajaxFun=Yii::app()->createUrl("controllerName/controllerFunction");
$ajaxReq = <<<JS
function samplefunction(var1,var2 ,dlg,refreshUrl){
$.ajax({
url: "$ajaxFun&var1="+var1+"&var2="+var2,
type: 'POST',
dataType: 'json',
success: function(data)
{
$("#htmlmessage").html(data.message);
$("#htmlmsgdialog").dialog("open");
}
});
if(dlg!=null ) $(dlg).dialog('close');
//window.location.href=refreshUrl
}
JS;
注意url:$ajaxFun,数据:&var1=“+var1+”&var2=“+var2”,
希望这会有帮助您的意思是没有进行ajax调用。?ajax调用的状态是什么。?我没有看到任何返回的状态,只是firebug中的url是红色的,没有执行任何操作。()你在FireBug中检查请求的响应我已经尝试了几种方法,但结果仍然是一样的。我的另一个ajax调用非常有效,就是这个。它没有抛出任何响应,只有参数、标题、帖子和cookie。
$.ajax({
url: "$ajaxFun",
data:"&var1="+var1+"&var2="+var2",
type: 'POST',
dataType: 'json',
success: function(data)
{
$("#htmlmessage").html(data.message);
$("#htmlmsgdialog").dialog("open");
}
});