Javascript Jquery/Ajax-如果回调成功,则返回自定义警报
我想使用jquery/javascript返回自定义警报框,因为返回的ajax值为0或1。1表示成功,0表示错误 现在我知道在我试过的时候这不起作用,但是我将把函数留在这里,这样你可以更清楚地看到我要做的事情Javascript Jquery/Ajax-如果回调成功,则返回自定义警报,javascript,php,jquery,Javascript,Php,Jquery,我想使用jquery/javascript返回自定义警报框,因为返回的ajax值为0或1。1表示成功,0表示错误 现在我知道在我试过的时候这不起作用,但是我将把函数留在这里,这样你可以更清楚地看到我要做的事情 <script> $("#login_form").submit(function() { $('.social').hide('slow'); if ($("#login_form").valid()) { $('.messagebox'
<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>
$(“#登录表单”).submit(函数(){
$('.social').hide('slow');
if($(“#登录表单”).valid(){
$('.messagebox').slideUp('slow');
var data1=$('#login_form').serialize();
$(“按钮”)。按钮(“加载”);
$.ajax({
类型:“POST”,
url:“includes/login.php”,
数据:数据1,
数据类型:“json”,
成功:功能(msg){
如果(msg.result==1){
展示成功();
setTimeout(“window.location.href='members.php';”,4000);
}否则{
$(“按钮”)。按钮(“重置”);
console.log(msg.result);
淋浴器();
}
}
});
}
返回false;
});
现在您可以看到,我想自动显示一个自定义警报框,该框存储在单独的函数中,用于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]);
webpackJsonp([15]{
240:函数(t,e){
$(文档).ready(函数(){
“严格使用”;
$(“#通知成功”)。在(“单击”,函数()上){
$.gritter.add({
类名称:“-成功”,
标题:“成功通知”,
text:“许多桌面发布软件包和网页编辑器现在使用Lorem Ipsum作为其模型文本。”,
时间:6e3
})
})
$(“#通知危险”)。在(“单击”,函数()上){
$.gritter.add({
类别名称:“-危险”,
标题:“危险通知”,
text:“许多桌面发布软件包和网页编辑器现在使用Lorem Ipsum作为其模型文本。”,
时间:6e3
})
})
$(“#通知信息”)。在(“单击”,函数()上){
$.gritter.add({
类别名称:“-info”,
标题:“信息通知”,
text:“许多桌面发布软件包和网页编辑器现在使用Lorem Ipsum作为其模型文本。”,
时间:6e3
})
})
函数showSuccess(){
$.gritter.add({
类名称:“-成功”,
标题:“成功登录”,
文本:“您已成功登录!
正在重定向您。”,
时间:6e3
})
};
函数名为ror(){
$.gritter.add({
类别名称:“-危险”,
标题:“发生错误”,
文本:“您输入了错误的凭据。”,
时间:6e3
})
};
})
},
334:函数(t,e,i){i(240)}
}, [334]);
你看,我试着在这个单独的文件中创建一些函数。
我在另一个index.php页面的底部调用此文件(我将代码存储在此页面顶部的页面)。您需要确保在第一个代码(表单提交)之前加载了showError()和showSucess()函数。尝试调用标头中的文件,而不是footer@seifeddineBesbes感谢您的快速回复,但我刚刚尝试了这个,它说函数没有定义-(淋浴ROR和showSuccess)好,这意味着顺序是正确的,所以您对控制台有什么想法(console.log(msg.result);)?@seifeddineBesbes我应该是的,因为它以前工作过,我只想更改警报样式。好的,您正在使用来管理通知。您可以在css文件中更改样式,并将适当的类添加到$.grister.add函数中吗?您需要确保函数在第一个代码(表单提交)之前加载。请尝试在头中调用该文件,而不是在footer@seifeddineBesbes感谢您的快速回复,但我刚刚尝试了这个,它说功能没有定义-(淋浴ROR和showSuccess)好的,这意味着顺序是正确的,所以您对控制台有什么想法吗(console.log(msg.result);?@seifeddineBesbes我应该是的,因为它以前工作过,我只想更改警报样式。好的,您正在使用来管理通知。您可以在css文件中更改样式,并将适当的类添加到$.grister.add函数中吗?