Ajax呼叫php存取mysql回傳JSON顯示的基本範例
Ajax呼叫php存取mysql回傳JSON顯示的基本範例
ajax_php.sql
— phpMyAdmin SQL Dump SET SQL_MODE = “NO_AUTO_VALUE_ON_ZERO”;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; — — ——————————————————– — CREATE TABLE IF NOT EXISTS `data` ( — INSERT INTO `data` (`id`, `value`) VALUES /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
api.php
<?php //————————————————————————– $tableName = “data”; //————————————————————————– //————————————————————————– //————————————————————————– ?> |
conn.php
<?php /***************************** *数据库连接 *****************************/ $conn = @mysql_connect(“localhost”,”root”,”usbw”); if (!$conn){ die(“資料庫連接失敗:” . mysql_error()); } mysql_select_db(“ajax_php”, $conn); mysql_query(“set character set ‘utf8′”); mysql_query(‘set names utf8’); ?> |
index.php
<!——————————————————————————————— I recommend going to http://jquery.com/ for the great documentation there about all of this <!——————————————————————————————— <script id=”source” language=”javascript” type=”text/javascript”> $(function () //——————————————————————————————- |