how to save data that come from json using ajax

how to save data that come from json using ajax

i have script that get from server data using ajax and it's good . but if i try to reuse the data that comfrom json in another script it's not know the variable .My guess because the Anonymous function . can anybody can tel me what i need to do to be able to reuse the data that come from the server.without made calling to the server again .

i attach the code that you can see .

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>First jQuery Mobile Example</title>
  5.     <!-- the three things that jQuery Mobile needs to work -->
  6.     <link rel="stylesheet" href="jquery.mobile-1.4.2/jquery.mobile-1.4.2.css" />
  7.     <script src="jquery-1.11.0.js" type="text/javascript"></script>
  8.     <script src="jquery.mobile-1.4.2/jquery.mobile-1.4.2.js" type="text/javascript"></script>
  9.     <meta name="viewport" content="width=device-width"/>

  10.     <script>
  11.         var output = '';

  12.         $.ajax({
  13.             url: 'https://c9.io/a1_shay/blabla/workspace/myFirstJson.json',
  14.             dataType: 'json',
  15.             type: 'get',
  16.             cache: false,
  17.             success: function(data)
  18.             {
  19.                 $(data.articles).each(function(index, value)
  20.                         {
  21.                             output += '<li>' +
  22.                                     '<a href="' + '#secondpage' + '" onclick=getDataById("'+ value.name +'")>' +
  23.                                     value.name + '</a>' + '</li>';
  24.                         }
  25.                 )
  26.                 console.log(output);
  27.                 var update = document.getElementById('listOfItemes');
  28.                 update.innerHTML = output;
  29.                 $('#listOfItemes').listview('refresh');
  30.             }
  31.         })

  32.     </script>

  33.     <script>
  34.         function getDataById(id)
  35.         {
  36.             var showOnTheScreeen;

  37.             $(data.articles).each(function(index, value)
  38.                     {


  39.                             alert(id);

  40.                     }
  41.             )
  42.         }
  43.     </script>
  44. </head>
  45. <body>


  46. <!-- This is the first page -->
  47. <section id="firstpage" data-role="page">
  48.     <div data-role="header">
  49.         <h1>Page Content Header</h1>
  50.     </div>

  51.     <ol data-role="listview" data-autodividers="true" data-filter="true" data-inset="true" id="listOfItemes">
  52.     </ol>

  53.     <div class="ui-content" role="main">
  54.         <p>This is the content on page 1</p>
  55.         <p><a href="#secondpage?aaa=bb" data-parm="john !!!!">Go to second page</a></p>
  56.     </div>
  57.     <div data-role="footer">
  58.         <h2>Page Content Footer</h2>
  59.     </div>
  60. </section>

  61. <!-- This is the second page -->
  62. <div id="secondpage" data-role="page">
  63.     <div data-role="header">
  64.         <h1>Page Content Header</h1>
  65.     </div>

  66.     <div id="detailsOnPerson">
  67.     </div>

  68.     <div class="ui-content" role="main">
  69.         <p>Page 2 has different content on it</p>
  70.         <p><a href="#firstpage">Go to first page</a></p>
  71.     </div>
  72.     <div data-role="footer">
  73.         <h2>Page Content Footer</h2>
  74.     </div>
  75. </div>

  76. </body>
  77. </html>