Tuesday, July 31, 2012

Load JSON Data Using Ajax

<!DOCTYPE html>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>

<script type="text/javascript" >

$( '#page1' ).live( 'pageshow',function(event, ui){

var liststr= "";
function getData() {                     
           url: "jsondata.php",
           dataType: 'jsonp',
           timeout: 9000,
           success: function(data, status) {
 $.each(data.movies, function(i, item) {                            
                   liststr+='<br>title '+item.title+'<br>year '+item.year+'  <br>description '+item.synopsis+'<br>';
           error: function() {
           var error = confirm('There was an error loading the data. Try loading the data again.');
           if (error){  


<div data-role="page" id="page1">
<div data-role="header">
<h1>Page 1</h1>
<div data-role="content">
<p>Page1 content goes here. Its a Page1.</p>
<div id="moviecontent"></div>
<a href="#page2" data-role="button" >Page2</a>
<div data-role="footer">
<h4>Page1 Footer</h4>