2017-06-09 63 views
0

以下是我的ajax調用代碼。php代碼點火器ajax調用甜蜜警報

var date = new Date(); 
yr = date.getFullYear(), 
    month = +date.getMonth() + 1 < 10 ? '0' + parseInt(date.getMonth() + 1) : date.getMonth() + 1, 
    day = +date.getDate() < 10 ? '0' + date.getDate() : date.getDate(), 
    newDate = yr + '-' + month + '-' + day; 
$("#dateupdated").val(newDate); 
var url = "<?php echo base_url("resident/updateresident/{$resident->id }"); ?>" 
$.ajax({ 
    url: url, 
    type: "POST", 
    data: new FormData(this), 
    contentType: false, 
    cache: false, 
    processData: false, 
    success: function (data) { 
     swal("Operation completed successfully."); 
     // var objs = $.parseJSON(data); 
     // var status=objs.status; 
    } 
}); 

它工作正常,但當我用甜蜜的警報確認彈出窗口時,它不會將數據發佈到控制器。有人可以告訴我如何擺脫這個?

新的代碼是:

swal({ 
    title: "Are you sure?", 
    text: "Are you sure that you want to cancel this order?", 
    type: "warning", 
    showCancelButton: true, 
    closeOnConfirm: false, 
    confirmButtonText: "Yes, cancel it!", 
    confirmButtonColor: "#ec6c62" 
}, function() { 
    alert(); 
    var date = new Date(); 
    yr = date.getFullYear(), 
     month = +date.getMonth() + 1 < 10 ? '0' + parseInt(date.getMonth() + 1) : date.getMonth() + 1, 
     day = +date.getDate() < 10 ? '0' + date.getDate() : date.getDate(), 
     newDate = yr + '-' + month + '-' + day; 
    $("#dateupdated").val(newDate); 
    var url = "<?php echo base_url("resident/updateresident/{$resident->id }"); ?>" 
    $.ajax({ 
     url: url, 
     type: "POST", 
     data: new FormData(this), 
     contentType: false, 
     cache: false, 
     processData: false, 
     success: function (data) { 
      swal("Operation completed successfully."); 
      // var objs = $.parseJSON(data); 
      // var status=objs.status;   
     } 
    }); 
}); 
+0

請正確格式化您的代碼 –

回答

0

我得到了解決你犯錯誤,這裏是下面的代碼,這將是肯定的工作,它進行測試。

swal({ 
    title: "Are you sure?", 
    text: "Are you sure that you want to cancel this order?", 
    type: "warning", 
    showCancelButton: true, 
    closeOnConfirm: false, 
    confirmButtonText: "Yes, cancel it!", 
    confirmButtonColor: "#ec6c62" 
}).then(function() { 
    // Your codes goes here 
}); 

這裏,我已經改變,function(){.then(function() {所以它會工作的代碼的函數內

而且我有SwaI位功能之後更改括弧您剛剛完成}但你必須完成})