我正在学习 JavaScript 的 Promise 函数,我希望按顺序运行以下命令:
我尝试了以下操作,但遇到了异常: 未捕获(承诺中)错误:侦听器通过返回 true 指示异步响应,但消息通道在收到响应之前关闭。
async function Do_System_Refresh()
{
let p = new Promise(function(Do_Refresh) {
Do_Refresh_UI();
});
await System_Refresh();
}
async function System_Refresh()
{
call ajax here
}
function Do_Refresh_UI()
{
alert('here do refresh called');
}
我做错了什么?
我需要建议,非常感谢。
如果您根本不打算使用它,为什么要在异步函数 Do_System_Refresh() 中使用 Promise?您不需要对 Do_Refresh_UI() 函数使用 Promise,它是同步的。
对于 System_Refresh(),当 Ajax 调用发生时,它已经绑定在异步函数中。 我希望你能得到答案:)