0
我想让它变成当我的ajax代码没有返回错误时,我得到了模态。我所有的代码都可以正常工作,只需要知道如何在没有错误时进行模式弹出。我有一个Ajax成功:函数,但我不知道这段代码如何工作,因为目前,它只有在点击按钮时才起作用。PHP - 成功注册后显示SweetAlert模态弹出窗口(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 =''的模式弹出:
<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>