angular - 以 Angular 发帖后重定向

标签 angular post angular6

您好,我正在写一个从我的站点到外部站点的发布请求。成功发布后,它应该自动重定向到给定的 url,其中参数作为第二个参数以该站点的形式显示,但它不会发生。我尝试将 responseType: "text" 作为第三个参数,这导致了我想要重定向到的响应页面的 html。如何在没有文本响应的情况下执行实际的重定向?

我的函数看起来像这样:

sendRequest() {
    //url that I am posting to and it should redirect to, params are given HTTPParams
    this.http.post(this.url,this.params)
      .subscribe(
        data => {
         //apparently following line is not needed.
         this.router.navigateByUrl(this.url);
        },
        error => {
          console.log("Error", error, this.params);
          this.data = error;
            },
        () => {
          console.log("POST is completed");
        });

  }

最佳答案

我找到了一个解决方案。正如 fjc 评论的那样,我只需要在带有 url 的 html 中使用 action="post"。以前我试过,但什么也没发生。经过几个小时的调试,我发现 Formsmodule 正在覆盖/阻止提交表单,所以这种方式不起作用。

关于angular - 以 Angular 发帖后重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51401210/

相关文章:

android - Kotlin POST 请求

android - 通过 HttpURLConnection (POST) 在 android 中发送多部分表单

angular - Angular Material 输入中的 ngx-translate 不显示初始负载时的平移,但在之后显示

html - Bootstrap 4 表格响应,水平和垂直滚动

asp.net-mvc - MVC Web API Angular App ('http://localhost:4200' 已被 CORS 策略阻止)

javascript - 使用 Angular 创建多级网格

php - 遍历数组并将数据上传到数据库中的行

javascript - 输入 radio 中的 ngModel?

angular - 如何从子组件中过滤父组件中的可观察对象?

angular - 在 Angular 5 中测试 FileSaver