我正试着在确认选项上使用YII的甜蜜警报。我有一个Ajax按钮,我希望弹出一个甜蜜的警告,一旦用户选择了确认或取消,我就可以继续处理Ajax请求,或者停止。
'ajax' => array(
'url'=>CController::createUrl('items/delete'),
'type'=>'POST',
'async'=>true,
'data'=>array('Item'=>$item['Item_id']),
'dataType'=>'json',
'enctype'=>'multipart/form-data',
'cache'=>false,
'beforeSend'=>'js:function(data)
{
var x = sweetalertDelete();
if(x){alert("aaaaaaa"); return true;}
else {alert("bbbbb"); return false;}
}',
'success'=>'function(data)
{
为了显示警告框,我正在使用beforesend。问题是,一旦出现该框,就会返回x,然后显示稍后看到的警报。这是我的警告代码:
function sweetalertDelete(){
swal({
title: "<?php echo Yii::t('app','misc.order_delete'); ?>",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
//swal("Deleted!", "Your imaginary file has been deleted.", "success");
if (isConfirm) {
alert("true");
return true;
}
else
{
alert("false");
return false;
}
});
}
我的问题是,如何才能使其返回isconcern的值?并且在单击“确认/取消”按钮之前,将不会发送Ajax请求?