bohan
bohan

Reputation: 1699

Share Json between html pages

I have used jQuery AJAX got a string of JSON in the login page. How can I use it in other pages. Are there some method to store the JSON and access it anywhere in my website. ps. I didn't use any other server script, it is only a html website. The JSON string is about 5K byte.

Upvotes: 1

Views: 1302

Answers (3)

Tim Green
Tim Green

Reputation: 3649

You can use localStorage.

// Store
localStorage.setItem("json", JSON.stringify(json));
// Retrieve
JSON.parse(localStorage.getItem("json"));

Upvotes: 5

Rohan Kumar
Rohan Kumar

Reputation: 40639

You can use localStorage or cookie to store your json.

Read about Web-storages

But remember cookie has size limitations, read this.

Upvotes: 1

user70585
user70585

Reputation: 1417

You can store json in .json files, and requests can go to those files and parse the responsetext with JSON.parse

Upvotes: 0

Related Questions