這是從mysql(一行)擷取表值的php腳本. &安培;将其作為JSON回應
$username = "user";
$password = "********";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to
connect to MySQL");
$selected = mysql_select_db("spec",$dbh) or die("Could not select first_test");
$query = "SELECT * FROM user_spec";
$result=mysql_query($query);
$outArray = array();
if ($result) {
while ($row = mysql_fetch_assoc($result)) $outArray[] = $row;
}
echo json_encode($outArray);
?>
這是接收的HTML檔案&列印json資料.
SRC = “http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js” >
// $(‘document’).ready(function(){
function Preload() {
$.getJSON("http://localhost/conn_mysql.php", function(jsonData){
$.each(jsonData, function(i,j)
{ alert(j.options);});
});}
// });