WBAccount.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. window.onload=function(){
  2. getData();
  3. }
  4. getData=function(){
  5. $.ajax({
  6. type: "get",
  7. url: "/selectall",
  8. data:{},
  9. dataType: "json",
  10. success: function (data) {
  11. let tbody=$("#warp")[0];
  12. tbody.innerHTML="";
  13. for(var i in data){
  14. let uid='"'+data[i].WbId+'"';
  15. let td="";
  16. let tr="";
  17. 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>";
  18. tr="<tr>"+td+"</tr>";
  19. $(tbody).append(tr);
  20. }
  21. }
  22. })
  23. }
  24. deleteData=function(id){
  25. var r=confirm("是否确定删除此微博号?")
  26. if (r==true)
  27. {
  28. $.ajax({
  29. type: "get",
  30. url: "/delete?id="+id,
  31. data:{},
  32. dataType: "json",
  33. success: function (data) {
  34. if(data=="success"){
  35. alert("删除成功!");
  36. getData();
  37. }else{
  38. alert("删除失败!");
  39. }
  40. }
  41. })
  42. return;
  43. }
  44. }
  45. insert=function(){
  46. let wbNum=$('.wbNum')[0].value;
  47. let wbName=$('.wbName')[0].value;
  48. $.ajax({
  49. type: "get",
  50. url: "/insert?num="+wbNum+"&name="+wbName,
  51. data:{},
  52. dataType: "json",
  53. success: function (data) {
  54. if(data=="success"){
  55. alert("插入成功!");
  56. show('.insertDiv');
  57. getData();
  58. }else{
  59. alert("插入失败!");
  60. }
  61. }
  62. })
  63. }
  64. update=function(id){
  65. show('.updateDiv');
  66. let wbName=$('.newName')[0];
  67. $.ajax({
  68. type: "get",
  69. url: "/selectbyid?id="+id,
  70. data:{},
  71. dataType: "json",
  72. success: function (data) {
  73. if(data.length!=0){
  74. wbName.value=data[0].WbName;
  75. }else{
  76. alert("查询失败!");
  77. }
  78. }
  79. })
  80. $(".update")[0].onclick=function(){
  81. if(wbName.value==""){
  82. alert("请填写要修改的微博名称!");
  83. return;
  84. }
  85. $.ajax({
  86. type: "get",
  87. url: "/update?id="+id+"&name="+wbName.value,
  88. data:{},
  89. dataType: "json",
  90. success: function (data) {
  91. if(data=="success"){
  92. alert("修改成功!");
  93. show('.updateDiv');
  94. getData();
  95. }else{
  96. alert("修改失败!");
  97. }
  98. }
  99. })
  100. };
  101. }
  102. show=function(el){
  103. let thisDiv=$(el)[0];
  104. if(thisDiv.style.display=="" || thisDiv.style.display=="none"){
  105. thisDiv.style.display="block";
  106. }else{
  107. thisDiv.style.display="none";
  108. }
  109. }