123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- window.onload=function(){
- getData();
- }
- getData=function(){
- $.ajax({
- type: "get",
- url: "/selectall",
- data:{},
- dataType: "json",
- success: function (data) {
- let tbody=$("#warp")[0];
- tbody.innerHTML="";
- for(var i in data){
- let uid='"'+data[i].WbId+'"';
- let td="";
- let tr="";
- td+="<td>"+data[i].WbNumber+"</td><td>"+data[i].WbName+"</td><td>"+data[i].AddTime+"</td><td><button onclick='update("+uid+")'>编辑</button><button onclick='deleteData("+uid+")'>删除</button></td>";
- tr="<tr>"+td+"</tr>";
- $(tbody).append(tr);
- }
- }
- })
- }
- deleteData=function(id){
- var r=confirm("是否确定删除此微博号?")
- if (r==true)
- {
- $.ajax({
- type: "get",
- url: "/delete?id="+id,
- data:{},
- dataType: "json",
- success: function (data) {
- if(data=="success"){
- alert("删除成功!");
- getData();
- }else{
- alert("删除失败!");
- }
- }
- })
- return;
- }
- }
- insert=function(){
- let wbNum=$('.wbNum')[0].value;
- let wbName=$('.wbName')[0].value;
- $.ajax({
- type: "get",
- url: "/insert?num="+wbNum+"&name="+wbName,
- data:{},
- dataType: "json",
- success: function (data) {
- if(data=="success"){
- alert("插入成功!");
- show('.insertDiv');
- getData();
- }else{
- alert("插入失败!");
- }
- }
- })
- }
- update=function(id){
- show('.updateDiv');
- let wbName=$('.newName')[0];
- $.ajax({
- type: "get",
- url: "/selectbyid?id="+id,
- data:{},
- dataType: "json",
- success: function (data) {
- if(data.length!=0){
- wbName.value=data[0].WbName;
- }else{
- alert("查询失败!");
- }
- }
- })
- $(".update")[0].onclick=function(){
- if(wbName.value==""){
- alert("请填写要修改的微博名称!");
- return;
- }
- $.ajax({
- type: "get",
- url: "/update?id="+id+"&name="+wbName.value,
- data:{},
- dataType: "json",
- success: function (data) {
- if(data=="success"){
- alert("修改成功!");
- show('.updateDiv');
- getData();
- }else{
- alert("修改失败!");
- }
- }
- })
- };
- }
- show=function(el){
- let thisDiv=$(el)[0];
- if(thisDiv.style.display=="" || thisDiv.style.display=="none"){
- thisDiv.style.display="block";
- }else{
- thisDiv.style.display="none";
- }
- }
|