美文网首页技术
jquery ajax 增删改查封装

jquery ajax 增删改查封装

作者: 啥啥啥娜娜 | 来源:发表于2017-08-22 13:56 被阅读90次

jQuery实例

$(function(){

//调用加载数据函数

loadstu();

//为添加按钮绑定一个添加动作

$("#aid").click(function(){

$("#fill").show();

$("#myform").show();

});

});

//加载学生信息

function loadstu(){

$.ajax({

url:"./model/action.php?a=index",

type:"GET",

dataType:"json",

success:function(data){

//alert(data);

varstr=null;

for(vari=0;i

"+data[i].id+"

"+data[i].name+"

"+data[i].sex+"

"+data[i].age+"

"+data[i].classid+"

删除

str+="";

}

$("#stuid tbody").empty();

$("#stuid tbody").append(str);

}

});

}

//删除函数

function doDel(sid,ob){

//执行ajax删除

if(confirm("确定要删除吗?"))

$.ajax({

url:"./model/action.php?a=del",

type:"POST",

data:{id:sid},

dataType:"json",

success:function(res){

//判断是否删除成功

if(res.num>0){

//alert(res.num);

$(ob).parents("tr").remove();

}

},

error:function(){

alert('error');

}

});

}

//执行添加

function doAdd(form){

//alert($(form).serialize());

$.ajax({

url:"./model/action.php?a=insert",

type:"POST",

data:$(form).serialize(),

dataType:"json",

success:function(res){

if(res.id>0){

$('#fill').hide();

$('#myform').hide();

$(form).find(":reset").trigger("click");

loadstu();//重新加载

}else{

alert('添加失败!');

}

}

});

return false;

}

jQuery实例--Ajax信息的增删改查等操作

学生信息

添加

学号姓名性别年龄班级号

操作

姓名:

年龄:

性别:

班级:

相关文章

网友评论

本文标题:jquery ajax 增删改查封装

本文链接:https://www.haomeiwen.com/subject/yfhldxtx.html