-1

My question is very simple... I need to make a regular post request in angular 4 app, like as html form post, that is that replace the window location..because if I do it using HttpClient, this makes an ajax POST... My question is... How to make a non ajax post request in angular 4?

Many Thanks!

Patricio Vargas
  • 5,236
  • 11
  • 49
  • 100
AlejoDev
  • 4,345
  • 9
  • 36
  • 67
  • Why do you even need "normal" POST request? Angular 4 is designed for single page applications which do not require page reloading. That's why all requests are async (via ajax). – M. Habib Oct 15 '18 at 04:09
  • This has nothing to do with angular, if you want to post a form in the traditional fashion use a traditional form. If you want to navigate somewhere use an ` – Avin Kavish Oct 15 '18 at 04:09
  • I need to integrate an external service ... to be precise a webcheckout ... I need to redirect the flow of my application to that external provider to make the payments and then return to my angular application – AlejoDev Oct 15 '18 at 04:13
  • idk exactly what you need but sounds like you are talking about http request. there's http request and httpClent. Try http request..but the cool kidz use httpClient. https://angular.io/api/common/http/HttpRequest – Patricio Vargas Oct 15 '18 at 04:39

1 Answers1

0

How about using HttpClient and setting or reloading location on success?

Here is an example how to do it:

let formdata = new FormData();
formdata.append('name', 'Max Mustermann');

this.http.post('http://myapiserver.com', formdata).subscribe(
    res => {
        // reloading location
        location.reload();

        // or navigate with:
        // this.router.navigateByUrl('/home')
        // or with
        // this._router.navigate(['Home']);
    }
);
Tommy
  • 2,355
  • 1
  • 19
  • 48