I have a php file that receives data from mySQL table. The mySQL table 'user_spec' has only one field 'options' that it returns. Then I convert returned data into JSON, under is code doing that.
<?php
$username = "user";
$password = "********";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect
to MySQL"); //print "Connected to MySQL<br>";
$selected = mysql_select_db("spec",$dbh) or die("Could not select first_test");
$query = "SELECT * FROM user_spec";
$result=mysql_query($query);
echo json_encode(mysql_fetch_assoc($result));
?>
then in an HTML file, I try to output data by this piece of code But it is not working. I will be very thankful for any help.
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
function Preload() {
$.getJSON("Dhttp://localhost/conn_mysql.php", function(json){
alert("JSON Data: " + json.user_spec);
});}
</script></head>
<body onLoad="Preload()">
</body>
</html>