Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用SweetAlert防止自动页面刷新_Javascript_Ruby On Rails_Sweetalert_Actioncable_Sweetalert2 - Fatal编程技术网

Javascript 使用SweetAlert防止自动页面刷新

Javascript 使用SweetAlert防止自动页面刷新,javascript,ruby-on-rails,sweetalert,actioncable,sweetalert2,Javascript,Ruby On Rails,Sweetalert,Actioncable,Sweetalert2,我的网站上有几个页面,在使用javascript或有时使用TurboLink甚至action cable的函数后刷新页面 我想使用SweetAlert来显示信息,但它并没有太大帮助,因为它在刷新之前就显示了,所以只在很短的时间内可见 基于前面的堆栈溢出问题,我构建了以下内容: Swal.fire({ 标题:“甜蜜!”, text:'你得到了${data.badge.description}徽章!`, imageUrl:data.badge\u image\u url, 图像宽度:200, 图像

我的网站上有几个页面,在使用javascript或有时使用TurboLink甚至action cable的函数后刷新页面

我想使用SweetAlert来显示信息,但它并没有太大帮助,因为它在刷新之前就显示了,所以只在很短的时间内可见

基于前面的堆栈溢出问题,我构建了以下内容:

Swal.fire({
标题:“甜蜜!”,
text:'你得到了${data.badge.description}徽章!`,
imageUrl:data.badge\u image\u url,
图像宽度:200,
图像高度:200,
imageAlt:“自定义图像”
},
功能(isConfirm){
如果(我确认){
window.location.reload();
}

});您可以尝试以下方法:

Swal.fire({
  title: 'Your message',
  icon: 'info',
  confirmButtonText: 'OK'
}).then(function(){
  window.location.reload();
})

您可以尝试以下方法:

Swal.fire({
  title: 'Your message',
  icon: 'info',
  confirmButtonText: 'OK'
}).then(function(){
  window.location.reload();
})

非常确定Sweet已经允许使用
wait
关键字。尝试使用wait Swal.fire({…})
它的意思是我不能在异步函数之外使用wait。你不能在顶级使用wait。将其包装在立即调用的异步函数中。示例:非常确定Sweet已经允许使用
await
关键字。尝试使用wait Swal.fire({…})它的意思是我不能在异步函数之外使用wait。你不能在顶级使用wait。将其包装在立即调用的异步函数中。例子: