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 .
- <!DOCTYPE html>
- <html>
- <head>
- <title>First jQuery Mobile Example</title>
- <!-- the three things that jQuery Mobile needs to work -->
- <link rel="stylesheet" href="jquery.mobile-1.4.2/jquery.mobile-1.4.2.css" />
- <script src="jquery-1.11.0.js" type="text/javascript"></script>
- <script src="jquery.mobile-1.4.2/jquery.mobile-1.4.2.js" type="text/javascript"></script>
- <meta name="viewport" content="width=device-width"/>
- <script>
- var output = '';
- $.ajax({
- url: 'https://c9.io/a1_shay/blabla/workspace/myFirstJson.json',
- dataType: 'json',
- type: 'get',
- cache: false,
- success: function(data)
- {
- $(data.articles).each(function(index, value)
- {
- output += '<li>' +
- '<a href="' + '#secondpage' + '" onclick=getDataById("'+ value.name +'")>' +
- value.name + '</a>' + '</li>';
- }
- )
- console.log(output);
- var update = document.getElementById('listOfItemes');
- update.innerHTML = output;
- $('#listOfItemes').listview('refresh');
- }
- })
- </script>
- <script>
- function getDataById(id)
- {
- var showOnTheScreeen;
- $(data.articles).each(function(index, value)
- {
- alert(id);
- }
- )
- }
- </script>
- </head>
- <body>
- <!-- This is the first page -->
- <section id="firstpage" data-role="page">
- <div data-role="header">
- <h1>Page Content Header</h1>
- </div>
- <ol data-role="listview" data-autodividers="true" data-filter="true" data-inset="true" id="listOfItemes">
- </ol>
- <div class="ui-content" role="main">
- <p>This is the content on page 1</p>
- <p><a href="#secondpage?aaa=bb" data-parm="john !!!!">Go to second page</a></p>
- </div>
- <div data-role="footer">
- <h2>Page Content Footer</h2>
- </div>
- </section>
- <!-- This is the second page -->
- <div id="secondpage" data-role="page">
- <div data-role="header">
- <h1>Page Content Header</h1>
- </div>
- <div id="detailsOnPerson">
- </div>
- <div class="ui-content" role="main">
- <p>Page 2 has different content on it</p>
- <p><a href="#firstpage">Go to first page</a></p>
- </div>
- <div data-role="footer">
- <h2>Page Content Footer</h2>
- </div>
- </div>
- </body>
- </html>