trying to get some info from my Mysql database to show up by connecting with phonegap through jquery to my PHP code..
however when I load up the page (either on my phone or on my PC) it comes up completely blank..
this is my jquery code which is in the phonegap build right before the <./body.> tag and I am including the latest jquery:
<script type="text/javascript">
$(document).ready(function(){
var output = $('#output');
$.ajax({
url: 'http://feedmysound.com/app/json.php',
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){
$.each(data, function(i,item){
var landmark = '<h1>'+item.title+'</h1>'
+ '<p>'+item.postin+'<br>'
+ item.user+'</p>';
output.append(landmark);
});
},
error: function(){
output.text('There was an error loading the data.');
}
});
});
</script>
and this is the php which is on the json.php:
<?php
$con = mysqli_connect("localhost", "xxxxxx","xxxxxx", "xxxxxx");
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
$result= mysqli_query($con, "SELECT * FROM xxxxx WHERE postin = 'main' ORDER BY datetime DESC")or die(mysqli_error($con));
$records = array();
while($row = mysqli_fetch_assoc($result))
{
$records[] = $row;
}
echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
?>
does anyone know whats wrong?
this is the fiddle.. not sure if thats even possible here but http://jsfiddle.net/h4dmF/9/
Kind regards
Your json.php data URL is loading up fine in a browser so there’s no issue with the MySQL connection.
I’m not sure about your app but the fiddle at least was wrapped in SCRIPT tags incorrectly. Here’s a working example:
http://jsfiddle.net/hansvedo/h4dmF/10
Since the app is loading data from a remote domain, you may need to use $.jsonp instead of $.ajax:
http://samcroft.co.uk/2010/loading-data-into-a-phonegap-app/