Código:
leyendo el json<?php header('Content-type: application/json'); $mysql_db_hostname = "localhost"; $mysql_db_user = "usuario"; $mysql_db_password = "pass"; $mysql_db_database = "db"; $con = @mysqli_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password, $mysql_db_database); mysqli_query($con, "CHARSET utf8"); mysqli_query($con, "SET NAMES 'utf8'"); if (!$con) { trigger_error('Could not connect to MySQL: ' . mysqli_connect_error()); } $var = array(); $sql = "SELECT * FROM locales ORDER BY id DESC"; $result = mysqli_query($con, $sql); while($obj = mysqli_fetch_object($result)) { $var[] = $obj; } echo $_GET['jsoncallback']. '(' . json_encode($var) . ');'; ?>
Código:
<!DOCTYPE html> <html> <head> <style>img{ height: 100px; float: left; }</style> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> </head> <body> <script> function get_jsonp_cross_domain() { $.ajax({ url: 'http://www.urlremoto/datosjsonphonegap.php',//esto con un archivo php type: 'GET',//tipo de petición dataType: 'jsonp',//tipo de datos jsonp: 'jsoncallback', error: function(xhr, status, error) { alert("error"); }, success: function(jsonp) { $(".data").html(jsonp.rubro); } }); } </script> <button onclick="get_jsonp_cross_domain()">pulsa</button> <div class="data"></div> </body> </html>