Cwebservice combined with jQuery to realize page turning without refresh

From , 3 Years ago, written in C#, viewed 155 times.
URL https://pastebin.vip/view/fcfe9c77
  1. <%@ Page Language="C#" AutoEventWireup="true" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  4.  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head id="Head1" runat="server">
  7.   <title></title>
  8.   <script src="jquery-1.6.4.min.js" type="text/javascript"></script>
  9. </head>
  10. <body>
  11.   <form id="form1" runat="server">
  12.   <div id="result">
  13.   </div>
  14.   </form>
  15.   <script type="text/javascript">
  16.     var pageNo = 1; //当前页号
  17.     var pageItems = 10; //每页显示的行数,这个数字与da.Fill(ds,pageNo,3,"gbook");里面的3保持一致
  18.     var MaxPage = pageItems;
  19.     function showPage(m) {
  20.       if (m == -1) {
  21.         if (pageNo < 2) {
  22.           alert("已经到了首页");
  23.           return;
  24.         };
  25.         MaxPage = pageItems;
  26.       }
  27.       else {
  28.         if (MaxPage < pageItems) {
  29.           alert("已经到了末页");
  30.           return;
  31.         };
  32.       }
  33.       pageNo += m;
  34.       getData();
  35.     }
  36.     $(document).ready(function () {
  37.       getData();
  38.     });
  39.     function getData() {
  40.       $.ajax({
  41.         type: "POST",
  42.         cache: false,
  43.         url: "WebService3.asmx/Select", /* 注意后面的名字对应CS的方法名称 */
  44.         data: { "pageNo": (pageNo - 1) * pageItems }, /* 注意参数的格式和名称 */
  45.         contentType: "application/x-www-form-urlencoded",
  46.         dataType: "xml",
  47.         error: function (result) {
  48.           alert(result.responseText);
  49.         },
  50.         success: function (data) {
  51.           MaxPage = $(data).find('Article').size(); /* Article是后台输出的表名称,要与后台对应 */
  52.           if (MaxPage == 0) {
  53.             $("#result").html("没有记录");
  54.             return;
  55.           }
  56.           t = "<table border='1'>";
  57.           $(data).find('Article').each(function (index, ele) {/* Article是后台输出的表名称,要与后台对应 */
  58.             var ArticleId = $(ele).find('ArticleId').text();
  59.             var Title = $(ele).find('Title').text();
  60.             t += "<tr>";
  61.             t += "<td>" + ArticleId + "</td>";
  62.             t += "<td>" + Title + "</td>";
  63.             t += "</tr>";
  64.           })
  65.           t += "</table>";
  66.           t += "<div><a href='' onclick='showPage(-1);return false;'>上一页</a> <a href='' onclick='showPage(1);return false;'>下一页</a></div>"
  67.           $("#result").html(t);
  68.         }
  69.       });
  70.     }
  71.   </script>
  72. </body>
  73. </html>
  74.  
  75.  
  76. //csharp/6895

Reply to "Cwebservice combined with jQuery to realize page turning without refresh"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website