Completely new to using AJAX and JSON with PHP and MYSQL. The code I have works with localhost, but returns nothing from the PHP files on 000webhost. Just wondering if there is any essential bits of code i'm missing out on here for an external server, or whether i have to add in extra code because of 000webhost itself (Although I don't imagine this being the case). Here is the code for one of my PHP files:
<?php
include 'dbconfig.php';
$con = mysql_connect($dbhost,$dbuser,$dbpass);
$dbs = mysql_select_db($dbname, $con);
$result = mysql_query("SELECT * FROM `desserts`");
$data = array();
while ( $row = mysql_fetch_row($result) )
{
$data[] = $row;
}
echo json_encode( $data );
?>
(This is just a test file, so i'm not worried about sql injections or anything of the sort)
And here is the JavaScript code to retrieve the data:
$.ajax({
url: 'http://appname.net/PHP/getDesserts.php',
data: "data",
dataType: 'json',
success: function(rows)
{
for(var i in rows)
{
var row = rows[i];
var startname = row[1];
var startprice = row[2];
var startpagelink = row[4];
$('#main_content').append('<b><a href="'+startpagelink+'">'+'<img id="sammich" src="sammich.jpg">'+'</br>'+startname+'</br><font color="400000">£'+startprice)
.append("</font><hr /></a></b>");
}
}
});
As i said this code works with localhost, but when I moved the php files to the server and changed the url to suit, is when i began to get this problem. Any help would be greatly appreciated.