PHP - 成功注册后显示SweetAlert模式弹出窗口(AJAX)

时间:2017-02-25 19:14:15

标签: php ajax registration

我想要这样做,以便当我的ajax代码没有返回错误时,我得到模态。我的所有代码都运行得很好,我只需要知道如果没有错误就可以进行模态弹出。我有一个ajax成功:功能,但我不确定这段代码是如何工作的,因为目前它只在单击一个按钮时才有效。

我正在使用SweetAlert JS文件

我的代码:

点击按钮时的工作模式:

  <script>
  !function(e){ "use strict";
   var t = function(){};
   t.prototype.init = function() {
      e("#sa-success").click(function() {
        swal("Registration Successful","Your registration was successful! Check your email and click on your activation link to be able to access your account.","success")
      }
        )
  },e.SweetAlert=new t,e.SweetAlert.Constructor=t}(window.jQuery),function(e){"use strict";e.SweetAlert.init()}(window.jQuery);
</script>

我的AJAX注册码我想做一次模态弹出一次msg =&#39; &#39; :

    <script>
        $(document).ready(function() {

    jQuery.validator.addMethod("noSpace", function(value, element) { 
     return value.indexOf(" ") < 0 && value != ""; 
  }, "Spaces are not allowed");

            $("#registered_form").submit(function() {

                if ($("#registered_form").valid()) {
                    var data1 = $('#registered_form').serialize();
                    $.ajax({
                        type: "POST",
                        url: "inc/pgs/register.php",
                        data: data1,
                        success: function(msg) {
                            console.log(msg);
                            if(msg == '') {
                                //setTimeout("window.location.href='login.php';",4000);
                            } else {
                                $("#result").html('<div class="alert alert-danger"><button type="button" class="close"></button>' + msg +'</div>').slideDown(100);
                                window.setTimeout(function()
                                {
                                    $(".alert").fadeTo(500, 0).slideUp(500, function(){
                                        $(this).remove(); 
                                    });
                                }, 3000);
                            }
                        }
                    });
                }
                return false;
            });
        });
    </script>

1 个答案:

答案 0 :(得分:0)

全部排序。我必须看SweetAlert手册才能看到它是如何工作的。我以前应该检查一下。

我只需要使用:

swal("Registration Success!", "Your registration was successful! Check your email and click on your activation link to be able to access your account.", "success");