将甜蜜警报2添加到jQuery函数中

时间:2016-10-11 08:45:31

标签: php jquery ajax

当我提交模态时调用此函数

function saveData() {

var name = $('#name').val();
var email = $('#email').val();
var phone = $('#phone').val();
var address = $('#address').val();

$.ajax({
    type: "POST",
    url: "server.php?p=add",
    data: "name=" + name + "&email=" + email + "&phone=" + phone + "&address=" + address,
    success: function () {
        viewData();
    }
});
}

在提交模式时,我无法添加甜蜜警报

    swal({
        title: "Success!",
        text: "added!",
        type: "success",
        timer: 3000,
        showConfirmButton: false
    });

1 个答案:

答案 0 :(得分:0)

最后我找出了解决方案

function saveData() {
var name = $('#name').val();
var email = $('#email').val();
var phone = $('#phone').val();
var address = $('#address').val();

$.ajax({
    type: "POST",
    url: "server.php?p=add",
    data: "name=" + name + "&email=" + email + "&phone=" + phone + "&address=" + address,
    success: function () {
        $('#addData').modal('hide');
        swal({
            title: "Success!",
            text: "added!",
            type: "success",
            timer: 3000,
            showConfirmButton: false
        });
        viewData();
    }
});
};

需要小心按特定顺序运行脚本:

  
      
  1. 的jquery.js
  2.   
  3. bootstrap.js
  4.