gpt4 book ai didi

javascript - 如何在 window.location 之前显示 msg 2 秒

转载 作者:行者123 更新时间:2023-11-28 06:12:24 24 4
gpt4 key购买 nike

JS:

  $.ajax({
url: url,
method: 'POST',
data: data,
}).done(id => {
this._handleMsg('data saved.');
const newUrl = dutils.urls.resolve( 'test', { test_id: id } );
window.location.replace(newUrl);
}).fail(( jqXHR, textStatus, errormsg ) => {
this._handleError('Sorry. Report not saved. Reason:' + errormsg); // eslint-disable-line no-alert
});



_handleMsg(msg) {
if (msg) {
$('#header .form-group').addClass('has-msg');
$('.report-error').html(msg).delay(200000).fadeIn(500000);
} else {
$('#header .form-group').removeClass('has-msg');
}
},

SCSS:

.report-error{
visibility: hidden;
text-align: center;
color: red;
}


.has-msg, .has-msg:focus, .has-msg:hover{
input {
border-color: #843534;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483;
background-color: #ffffff;
outline: 0;
}
label, .report-error{
visibility: visible;
color: green;
font-size:30px;
}
}

我需要显示消息“数据已保存”。持续 2 秒,然后重定向到另一个 url。但似乎 $('.report-error').html(msg).delay(200000).fadeIn(500000); 不起作用。

有什么想法吗?谢谢

更新

 203         this._handleMsg('data saved.');
204 setTimeout(()=>{
205 const newUrl = dutils.urls.resolve( 'test', { test_id: id } );
206 window.location.replace(newUrl);
207 }, 2000);

最佳答案

$.ajax({
url: url,
method: 'POST',
data: data,
}).done(id => {
this._handleMsg('data saved.');
const newUrl = dutils.urls.resolve( 'test', { test_id: id } );
//below function will call after 2s that solve your purpose
setTimeout(function () { window.location.replace(newUrl); }, 2000);

}).fail(( jqXHR, textStatus, errormsg ) => {
this._handleError('Sorry. Report not saved. Reason:' + errormsg); // eslint-disable-line no-alert
});

关于javascript - 如何在 window.location 之前显示 msg 2 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36094196/

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