【问题标题】:Send post request in angular 6 without wait to response以角度 6 发送发布请求,无需等待响应
【发布时间】:2018-08-26 14:39:53
【问题描述】:

当我关闭我的应用程序时,我想从 Angular 6 应用程序发送一个 http post 请求。 我的问题是当我关闭应用程序时,http 请求被中止。 如何发送 http post 请求而不以这种方式中止它?另外我不关心结果,我只希望请求在服务器中完成。

【问题讨论】:

    标签: javascript angular angular6 http-post dom-events


    【解决方案1】:

    但是它不起作用,因为页面正在关闭并且它没有到达订阅并且在网络中它说请求被取消了

    【讨论】:

    【解决方案2】:

    我会订阅,因为如果不订阅,它就不会触发。然后对响应不做任何事情。

    this.http.post( url, body, headers ).subscribe(
       data => {
                // don't do nothing
               }
       );
    

    【讨论】:

      【解决方案3】:

      然后(假设您使用的是 HttpClient),您将只调用没有订阅逻辑的方法:

      this.http.post(URL,BODY).subscribe();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-12
        • 2015-01-06
        • 2013-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-30
        相关资源
        最近更新 更多