php代码点火器带有ajax调用的甜蜜警报

时间:2017-06-09 16:51:23

标签: php ajax codeigniter sweetalert

以下是我的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;           
        }
    });
});

1 个答案:

答案 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 () {,因此它将在您的函数中使用代码

并且我在swal功能后更改了括号,您刚刚完成}但是您必须完成})