user3386779
user3386779

Reputation: 7215

passing the ajax response data to another page after ajax call on success

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
      }
});

Upvotes: 3

Views: 2080

Answers (1)

Sebastian B.
Sebastian B.

Reputation: 2211

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.

Upvotes: 3

Related Questions