在提交ajax时,确认对话框无效

时间:2014-07-23 08:09:10

标签: jquery ajax codeigniter

请参阅以下脚本:

function is_holiday()
   {
       var start = $("#datepicker").val(),
       end = $("#datepicker1").val();
       var dateAr = start.split('/');
       var start_date = dateAr[2] + '-' + dateAr[1] + '-' + dateAr[0];
       var dateAr2 = end.split('/');
       var end_date = dateAr2[2] + '-' + dateAr2[1] + '-' + dateAr2[0];
       var confirm_data = 0;
       var holiday_url = '<?php echo base_url(); ?>userappointments/multiday/'+start_date+'/'+end_date;
       $.ajax
       ({
            type: "POST",
            url: holiday_url,
            success: function(result)
            {
               if(result != '')
               {  
                  window.confirm(result + "Are you sure you want to proceed?");
               }
            }
       });
    }

表单代码在

下面
<form onsubmit="return is_holiday();"  method="post" id="form1" action="<?php echo base_url(); ?>userappointments/newappointment/<?php if(isset($app_cus)) { echo '?customer_id='.$app_cus;} ?>">

提交表格的时候提交了,但是ajax没有用确认对话框打电话。我们想要当我们提交那个时间它首先进入ajax然后如果它得到结果它应该显示确认框然后点击确定。然后提交表格。

1 个答案:

答案 0 :(得分:1)

你试过吗

confirm(result + "Are you sure you want to proceed?");

而不是

window.confirm(result + "Are you sure you want to proceed?");

编辑 - 试试这个:

function is_holiday(){
   var start = $("#datepicker").val(),
   end = $("#datepicker1").val();
   var dateAr = start.split('/');
   var start_date = dateAr[2] + '-' + dateAr[1] + '-' + dateAr[0];
   var dateAr2 = end.split('/');
   var end_date = dateAr2[2] + '-' + dateAr2[1] + '-' + dateAr2[0];
   var confirm_data = 0;
   var holiday_url = '<?php echo base_url(); ?>userappointments/multiday/'+start_date+'/'+end_date;
   $.ajax
   ({
        type: "POST",
        url: holiday_url,
        success: function(result)
        {
           if(result != '')
           {  
              if(confirm(result + "Are you sure you want to proceed?")){
                // If it's confirmed, do stuff here
                alert('Confirmed');
              }
              return false;
           }
        }
   });
}