Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace entire DOM (page) with response from $http in AngularJS

I have HTML AngualrJS application which works as follow:

  1. User types payment info on the form, form does not have action attribute set
  2. user clicks submit
  3. AngularJS intercepts data, processes payment and sends requests to server.

This is where controller receives transaction confirmation details from my PHP:

this.stripeResponseHandler = function (status, response) {
...
$http ({
        method: 'POST',
        url: 'https://server/billpay/charge.php',
        data: postData  
}).then (function (response) {
        console.log (response.data);
        that.result = response.data;
        that.isSaving=1;
}, function (response) {
        console.log ("failed %s", response);
        that.isSaving=1;
})

Problem:

I need to replace entire existing page (with the form) to the full HTML page (with CSS, HTML, JS) returned by the server.

Server returns the receipt which user can just print for the records.

Essentially I don't want to just inject server's response to DIV (or similar) on the current page, instead entire new page needs to be re-rendered from the server response.

How would I do this?

Thanks!!

like image 984
leon Avatar asked Apr 22 '26 01:04

leon


1 Answers

create another page with (CSS, HTML, JS) and after form submission redirect to that page with server response data.

like image 164
Dimi Mikadze Avatar answered Apr 23 '26 15:04

Dimi Mikadze