nshunz
nshunz

Reputation: 263

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?

Upvotes: 3

Views: 76

Answers (3)

Daniel Aragão
Daniel Aragão

Reputation: 155

You should use your backend language to do that, as far as i know, you can't control (for security reasons) another tab or document outside the one you are using.

My solution would be, using your backend lang, redirect sending the data from the application server.

BUT, if the page you are redirecting belongs to the same domain you can do it from the localStorage as @Willem van der Veen said

Upvotes: 1

user10463086
user10463086

Reputation:

redirect with php then send data to page! (flash message technique)

Upvotes: 0

Willem van der Veen
Willem van der Veen

Reputation: 36660

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()

Upvotes: 3

Related Questions