3

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?

4
  • You can use local storage for this.. for more ref.check developer.mozilla.org/en-US/docs/Web/API/Window/localStorage Commented Oct 5, 2018 at 17:34
  • Post the data to the next page and real the post body. Commented Oct 5, 2018 at 17:35
  • @epascarello could you please elaborate? Commented Oct 5, 2018 at 17:57
  • HTML forms, post.... Commented Oct 5, 2018 at 18:00

3 Answers 3

3

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()
Sign up to request clarification or add additional context in comments.

2 Comments

I love retrieving with set!
Ye nice one :p!
1

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.