0

Suppose I have a php script that returns employee details e.g name and address in json encoded format.

I loop through the data returned and print only their names out on a list, not needing to display other data on initial page load.

$.post( "./php/getEmployees.php",function( data ) {
$.each(data, function (index, value) {
    $("#list").append('<li><a href="#section2">'+value.title+'</a></li>');
});
},"json");

Now I will have a list of employee names on screen for the user to see.

If they were to click on an employee I want to display the rest of their details that was returned in the getEmployees.php script.

How would I store data from my script to be accessed later?

Martin54
  • 1,349
  • 2
  • 13
  • 34
user2202098
  • 830
  • 1
  • 9
  • 24
  • 2
    Use localStore http://stackoverflow.com/questions/9404813/how-to-view-or-edit-localstorage – Mario Santini Mar 04 '17 at 22:21
  • The `value` object will giver you the details which you can append as a div with details. Make this div invisible initially then when they click on Employee you can enable this div. – bhantol Mar 04 '17 at 22:22
  • If its not a huge list of employees, you can store it in an array. – CaptainHere Mar 04 '17 at 22:29

1 Answers1

1

you can use localStorage

example of usage:

var person = {name:'some name', contact: {phone:'xxxxxxxx', address: 'yyyyyyyy'}}
// store
localStorage.setItem('person', JSON.stringify(person))
// retrieve
var myPerson = JSON.parse(localStorage.getItem('person'))
console.log(myPerson.contact)

// Output:
// Object {phone: "xxxxxxxx", address: "yyyyyyyy"}
elmiomar
  • 1,747
  • 2
  • 17
  • 27