Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use returned AJAX data on another page

I have an Ajax call that returns some json data when it is successful.

This data needs to be displayed on another page that user will be redirected to.

window.location.replace('http://example.com/newpage');

And on this page the data should be displayed.

Apart from sessions/cookies is there any other way to carry this data? Or is sessions the normal way this is done?

like image 332
nshunz Avatar asked Dec 21 '25 03:12

nshunz


1 Answers

Use localstorage the api. It works in the following manner:

Set an item:

localStorage.setItem('myCat', 'Tom');

Retrieve an item:

localStorage.getItem('myCat');


localstorage offers string data to be stored accross multiple browser sessions. If you want to store object and/or arrays you have to serialize/deserialize them using:

  • json.stringify()
  • json.parse()
like image 169
Willem van der Veen Avatar answered Dec 22 '25 15:12

Willem van der Veen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!