This article introduces a simple example of ajax php mysql reading the database. It has a certain reference value. Now I share it with you. Friends in need can refer to it
1. Create a database
create database ajaxdemo default charset utf8;
use ajaxdemo;
Create a table and insert data
CREATE TABLE `ajaxtest` ( `userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户id', `username` varchar(50) NOT NULL COMMENT '用户名', `userpass` varchar(50) NOT NULL COMMENT '密码', `userage` int(11) NOT NULL COMMENT '年龄', `usersex` varchar(1) NOT NULL COMMENT '性别', PRIMARY KEY (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `ajaxtest` VALUES ('1', '李四', 'lisi', '15', '男'); INSERT INTO `ajaxtest` VALUES ('2', '张三', 'lisi', '20', '女'); INSERT INTO `ajaxtest` VALUES ('3', '王五', 'lisi', '25', '男'); INSERT INTO `ajaxtest` VALUES ('4', '韩梅梅', 'lisi', '25', '男'); INSERT INTO `ajaxtest` VALUES ('5', '张莉', 'lisi', '25', '女');
<html> <head> <meta charset="utf-8"/> <title>ajax实例</title> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body style="height: 800px;"> <p class="container"> <p class="panel panel-default" style="margin-top: 100px;text-align: center;"> <p class="panel-heading"> Ajax实例 </p> <p class="panel-body"> <form class="navbar-form navbar-center" role="search" name="myform"> <p class="form-group"> <label> 年龄:<input type="number" class="form-control" placeholder="Age" name="userage" id='userage'/> </label> </p> <select class="form-control" id="usersex" name="usersex"> <option value="男">男</option> <option value="女">女</option> </select> <button type="button" class="btn btn-default" onclick='ajaxFunction()'>提交</button> </form> <table class="table table-condensed table-bordered" id="ajaxp"></table> <p>SQL语句:<pre id="sql">