我想使用jquery / javascript返回我的自定义警报框,返回的ajax值为0或1. 1表示成功,0表示错误。
现在我知道这在我尝试的时候不会起作用,但是我会把这些功能留在这里,这样你就可以看到我想要做的更清楚。
<script>
$("#login_form").submit(function() {
$('.social').hide('slow');
if ($("#login_form").valid()) {
$('.messagebox').slideUp('slow');
var data1 = $('#login_form').serialize();
$("button").button('loading');
$.ajax({
type: "POST",
url: "includes/login.php",
data: data1,
dataType: 'json',
success: function(msg) {
if (msg.result == 1) {
showSuccess();
setTimeout("window.location.href='members.php';",4000);
} else {
$("button").button('reset');
console.log(msg.result);
showError();
}
}
});
}
return false;
});
</script>
现在您可以看到,如果msg.result == 1或0,我想自动显示存储在单独函数中的自定义警报框。 我不想点击它,我希望它成功和错误回调。
我的自定义提醒框是:
webpackJsonp([15], {
240: function(t, e) {
$(document).ready(function() {
"use strict";
$("#notification-success").on("click", function() {
$.gritter.add({
class_name: "-success",
title: "Success Notification",
text: "Many desktop publishing packages and web page editors now use Lorem Ipsum as their model text.",
time: 6e3
})
})
$("#notification-danger").on("click", function() {
$.gritter.add({
class_name: "-danger",
title: "Danger Notification",
text: "Many desktop publishing packages and web page editors now use Lorem Ipsum as their model text.",
time: 6e3
})
})
$("#notification-info").on("click", function() {
$.gritter.add({
class_name: "-info",
title: "Info Notification",
text: "Many desktop publishing packages and web page editors now use Lorem Ipsum as their model text.",
time: 6e3
})
})
function showSuccess() {
$.gritter.add({
class_name: "-success",
title: "Successful Login",
text: "You have successfully logged in!<br>Redirecting you now.",
time: 6e3
})
};
function showError() {
$.gritter.add({
class_name: "-danger",
title: "An error occured",
text: "You have entered in the wrong credentials.",
time: 6e3
})
};
})
},
334: function(t, e, i) { i(240) }
}, [334]);
你看我试过在这个单独的文件中创建一些函数。 我将此文件称为我的另一个index.php页面的底部(我将代码存储在本页顶部的页面。