获取保持活动状态未按预期工作

kuarbcqp  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(208)

我正在开发angularjs 1.6版本。在我的app.controller.js中,我添加了三个事件侦听器并附加了一个deleteStustudent方法。

window.addEventListener('beforeunload', this.deleteStudent, false);
    window.addEventListener(
      'unload',
      () => {
        this.deleteStudent
      },
      false
    );
    window.addEventListener('pagehide', this.deleteStudent, false);

deleteStudent() {
 let Url = "http://localhost:9000/students/3";
    const deleteMethod = {
      method: 'DELETE',
      headers: {
        'Content-Type': 'application/json'
      },
      keepalive: true
    };
    fetch(Url, deleteMethod);
}

api调用未到达后端,但在chrome网络选项卡上被列为挂起状态。

  • 上面使用的deleteapi是在nodejs中创建的,可以与postman一起正常工作。

我只能在页面卸载时调用此api,建议使用带有keep alive属性true的fetch api或使用sendbeacon(),但我的后端api类型为delete,因此我不能使用sendbeacon(),因为它只支持post。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题