0

I have ajax call and pull the data and I want to send the response to next page in ajax success and get the data in drilldown.html

 $.ajax({
         type: "POST",
         url: "drilldown.php",
         data:data,
        success: function(response){
          window.location.href = 'drilldown.php'; // want to post the data this in redirection
      }
});
user3386779
  • 5,675
  • 12
  • 49
  • 109
  • The only way I see this is by adding the response data as a query parameter to your URL – Hobroker May 26 '20 at 12:42
  • Is it possible in post call – user3386779 May 26 '20 at 12:43
  • Various options: POST-redirect (submit the form to the new url, not via ajax), localStorage, sessionStorage, cookie, URL parameters. – freedomn-m May 26 '20 at 12:44
  • 1
    If your ajax url is the same as the location you want to redirect, why not go there directly? There seems to be a problem with your flow. You send an ajax request to drilldown, and then redirect the user to drilldown. – Romi Halasz May 26 '20 at 12:44
  • 1
    It is possible, check this answer https://stackoverflow.com/questions/8389646/send-post-data-on-redirect-with-javascript-jquery – Hobroker May 26 '20 at 12:44
  • Does this answer your question? [Send POST data on redirect with JavaScript/jQuery?](https://stackoverflow.com/questions/8389646/send-post-data-on-redirect-with-javascript-jquery) – freedomn-m May 26 '20 at 12:45
  • Also, you can't POST data to an HTML page. You would need a script, like PHP or Node. – Romi Halasz May 26 '20 at 12:45
  • 1
    I agree with @RomiHalasz, maybe rethink your flow? – Hobroker May 26 '20 at 12:46
  • @freedomn-m How do you run a PHP script inside an HTML file? – Romi Halasz May 26 '20 at 12:48

1 Answers1

0

If there is no server-side involved, you can save the data using Window.localStorage (check if browser compatibility is OK for you)

 $.ajax({
         type: "POST",
         url: "drilldown.html",
         data:data,
        success: function(response){
          localStorage.setItem('myData', data);
          window.location.href = 'drilldown.html'; // want to post the data this in redirection
      }
});

On the drilldown.html page, you can read the data with JavaScript by

var data = localStorage.getItem('myData');

There's also sessionStorage which will be cleaned up after browser restart.

Sebastian B.
  • 2,026
  • 13
  • 21