gpt4 book ai didi

javascript - 为什么MVC Sweet Alert会自动关闭?

转载 作者:行者123 更新时间:2023-12-02 14:25:42 26 4
gpt4 key购买 nike

下面是我的编码。请告知为什么甜蜜警报只弹出不到 1 秒然后自动重定向到另一个页面。

来自 HTML:

$.ajax({
url: "/ABC/AddST/",
data: {
"username": $("#username").val(),
"fullname": $("#fullname").val()
},
type: "POST"
}).success(function(data) {
swal({
title: "Done!",
text: "Sales Team was successfully added!",
type: "success"
}, function() {
window.location.href = '/ABC/STList';
});
}).error(function(data) {
swal("Oops", "We couldn't connect to the server!", "error");
});

来自 Controller :

[HttpPost]
public ActionResult AddSalesTeam(string username, string fullname)
{
var st = new Sales();

if (ModelState.IsValid)
{
st.Username = username;
st.FullName = fullname;
db.User.Add(st);
db.SaveChanges();
return RedirectToAction("SalesTeamList");
}
return View();
}

最佳答案

你需要给它一个计时器。

swal({
title: "Done!",
text: "Sales Team was successfully added!",
type: "success",
timer: 1000, // Wait 1 second
showConfirmButton: false // No reason to show the button
}, function() {
window.location.href = '/ABC/STList';
});

关于javascript - 为什么MVC Sweet Alert会自动关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38271878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com