JavaScript Promise - 未捕获(承诺中)

问题描述 投票:0回答:1

我正在学习 JavaScript 的 Promise 函数,我希望按顺序运行以下命令:

  • Do_System_Refresh(); --> 在此函数中,出于某些目的,我在 System_Refresh() 中调用 AJAX 函数。
  • Do_Refresh_UI();

我尝试了以下操作,但遇到了异常: 未捕获(承诺中)错误:侦听器通过返回 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');
} 

我做错了什么?

我需要建议,非常感谢。

javascript
1个回答
0
投票

如果您根本不打算使用它,为什么要在异步函数 Do_System_Refresh() 中使用 Promise?您不需要对 Do_Refresh_UI() 函数使用 Promise,它是同步的。

对于 System_Refresh(),当 Ajax 调用发生时,它已经绑定在异步函数中。 我希望你能得到答案:)

© www.soinside.com 2019 - 2024. All rights reserved.