conectando.php
Código:
$con = @mysqli_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password, $mysql_db_database); if (!$con) { trigger_error('Could not connect to MySQL: ' . mysqli_connect_error()); } $var = array(); $sql = "SELECT * FROM wp_posts WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 10"; $result = mysqli_query($con, $sql); while($obj = mysqli_fetch_object($result)) { $var[] = $obj; } echo '{"users":'.json_encode($var).'}';
Código:
<article data-role="content" id="jsondata"> <ul data-role="listview" data-filter="true"> </ul> </article> <script type="text/javascript"> $(document).ready(function(){ var url="conectando.php"; $("#jsondata ul").html(""); $.getJSON(url,function(data){ $.each(data.users, function(i,user){ var newRow = "<li>" +"<h1>"+user.post_title+"</h1>" +"<p>"+user.post_date+"</p>" +"</li>" ; $(newRow).appendTo("#jsondata ul"); }); }); }); </script>