js+php表格的增删改差
2021-01-22 17:14
阅读:550
YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
标签:list username echo open 服务 cas send inner view
js+php表格的增删改差
实现的效果如下图所示:
{{uploading-image-727245.png(uploading...)}}
html基础页面
Document
学生成绩管理系统
学生学号
学生姓名
语文成绩
数学成绩
英语成绩
操作
通过ajax传数据-ajax.js
export{
post,
get,
ajax
}
function post(){
var argus =Object.assign({"method" :"post"},...arguments)
var g = new Ajax(argus);
g.init();
g.type()
}
function get(){
var argus =Object.assign({"method" :"get"},...arguments)
var g = new Ajax(argus);
g.init();
g.type()
}
// function ajax(){
// var a =new Ajax(...arguments);
// a.init();
// a.type();
// }
function ajax(){
var a = new Ajax(...arguments);
a.init();
a.type()
}
class Ajax{
constructor({method,url,data,success,error}){
this.method = method;
this.url = url;
this.data = data;
this.success = success;
this.error = error;
}
init(){
var xhr = null;
try{
xhr = new XMLHttpRequest;
}catch{
xhr = new ActiveXObject("XMLHTTP");
}
return xhr;
}
type(){
var xhr= this.init()
var querystring=""
if(this.data){
querystring = this.queryString(this.data);
}
if(this.method=="get"){
xhr.open(this.method,this.url+"?"+querystring,true);
xhr.send();
}else{
xhr.open(this.method,this.url,true);
xhr.setRequestHeader(‘content-type‘, "application/x-www-form-urlencoded");
xhr.send(querystring);
}
xhr.onreadystatechange = ()=>{
if(xhr.readyState ==4){
if(xhr.status==200){
if(this.success){
this.success(xhr.responseText)
}
}else{
if(this.error){
this.error("error"+xhr.status)
}
}
}
}
}
queryString(dataObj){
var str=‘‘;
for(var attr in dataObj){
str+=`${attr}=${dataObj[attr]}&`
}
return str.substring(0,str.length-1)
}
}
分页-paging.php
$page,
"count" => $count,
"pages" => $pages,
"limit" => $limit,
"skip" => $skip,
"userlist" => array()
);
$sql2 = "SELECT * FROM students LIMIT {$skip}, {$limit}";
$res2 = mysqli_query($link, $sql2);
while($row2 = mysqli_fetch_assoc($res2)){
array_push($msg[‘userlist‘], $row2);
}
echo json_encode($msg);
mysqli_close($link);
?>
数据添加 insert.php
数据删除 delete.php
数据修改-查找update.php
数据修改-更新 update1.php
js+php表格的增删改差
标签:list username echo open 服务 cas send inner view
原文地址:https://www.cnblogs.com/cupid10/p/13284473.html
下一篇:jQuery DOM操作
评论
亲,登录后才可以留言!