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>