php 使用sweetalert点击确定后如何重新加载页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36300919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to reload a page after clicked ok using sweetalert
提问by Fil
Hello I have a code using sweetalert
你好,我有一个使用 sweetalert 的代码
swal("Good job!", "You clicked the button!", "success")
this code will pop-up a message and has a button okay, what I like to do is I want to refresh the page after I click the okay button.
这段代码会弹出一条消息并有一个好的按钮,我喜欢做的是我想在我点击好的按钮后刷新页面。
Can I do that?
我可以这样做吗?
回答by Yoshioka
You can try this, its work for me..
你可以试试这个,它对我有用..
swal({title: "Good job", text: "You clicked the button!", type: "success"},
function(){
location.reload();
}
);
回答by Leo C
The answer from Yoshioka did not work for me, I did this and it worked perfectly:
Yoshioka 的回答对我不起作用,我这样做了,而且效果很好:
swal({title: "Good job", text: "You clicked the button!", type:
"success"}).then(function(){
location.reload();
}
);
回答by Jan Heil
Use the callback function...
使用回调函数...
Swal.fire({
// Swal Setting's
}).then((result) => {
// Reload the Page
location.reload();
});
回答by Rohallah Hatami
You can check confirm by this:
您可以通过以下方式检查确认:
swal({
title: "Good job",
text: "You clicked the button!",
icon: "success",
buttons: [
'NO',
'YES'
],
}).then(function(isConfirm) {
if (isConfirm) {
location.reload();
} else {
//if no clicked => do something else
}
});
回答by Kingston Fortune
I use sweet alert 2 and this works for me
我使用甜蜜警报 2,这对我有用
swal("Good job!", "You clicked the button!","success").then( () => {
location.href = 'somepage.html'
})
‘'' The answers making use of location.reload() is going to trigger your form to attempt to resubmit over and over again, thats why you should use location.href instead.
''' 使用 location.reload() 的答案将触发您的表单一次又一次地尝试重新提交,这就是您应该使用 location.href 的原因。
回答by Rohit Dhiman
For Sweet Alert 2, this will work.
对于 Sweet Alert 2,这将起作用。
swal("Good job!", "You clicked the button!", "success").then(function(){
location.reload();
});
As you can see migration guide
正如您所看到的迁移指南
Sweet Alert 2 uses Promise
Sweet Alert 2 使用Promise
回答by Rahul Gupta
In Sweet Alert 2, there is callback function where you can implement your logic :
在Sweet Alert 2 中,有回调函数,您可以在其中实现您的逻辑:
Swal.fire({
title: 'Great job',
text: "You clicked the button!",
type: 'success',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
if(result){
// Do Stuff here for success
location.reload();
}else{
// something other stuff
}
})