数据提交成功后如何避免alert被window.location.reload()影响

数据提交成功用alert提示,但页面立马就重载了

alert("提交成功!");
window.location.reload();

如何避免?

方法一:

setTimeout 延迟3秒效果:

                alert('提交成功!');
                setTimeout(function () {
                    window.location.reload();
                }, 3000);

方法二:

(在w3School测试有效,但是在项目中测试还是立马刷新...)

new Promise(function (resolve, reject) {
        resolve(alert('提交成功'))
    }).then(() => {
        window.location.reload();
    })

 

posted on 2017-08-17 15:41  風云  阅读(1798)  评论(0编辑  收藏  举报

导航