滚动条加载数据
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>动态加载</title> <style type="text/css">ul{ list-style:none;}li{border-bottom:1px dashed #79A7E2; margin-bottom:20px;} </style> <script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script> <script type="text/javascript"> var _times; var _loading; var _pageindex; $(function () { _loading = $("#loading"); _times = setInterval("Comment()", 1000); }); function load() { _pageindex = $.trim(_loading.attr("pageindex")); $.ajax({ type: "post", dataType: "json", async: false, url: "/ajax/AjaxGroup.aspx", data: { action: "getArea", "pageindex": _pageindex }, success: function (data) { if (data == null) { _loading.html("数据已读取完成"); clearInterval(_times); } else { var _l = data.length; _loading.attr("pageindex", parseInt(_pageindex) + 1); var _temp = ""; for (var i = 0; i < _l; i++) { _temp += "<li>" + data[i]["name"] + "</li>"; } if (_temp.length > 0) { //$("#info").append(_temp); $(_temp).insertBefore(_loading); } } }, error: function (ee1, ee2, ee3) { _loading.css("color", "red"); _loading.html("数据读取出错!"); } }); } function Comment() { var top = document.documentElement.scrollTop + document.body.scrollTop; var textheight = $(document).height(); if ((textheight - top - $(window).height()) < 100) { load(); } } </script> </head> <body> <ul><li id="loading" style="color:Green;" pageindex="1"><img src="/images/loading.gif" alt="系统正在提取数据" />请稍后,系统正在提取数据。。。</li></ul> <label>asdfasdfasfdasdf</label> </body> </html>
Util gjBll = new Util(); MySqlExecute mseBll = new MySqlExecute(); protected void Page_Load(object sender, EventArgs e) { string host = Request.UrlReferrer.Host; if (string.Compare(host, Request.Url.Host) > 0) { return; } Response.Clear(); string action = gjBll.getFormString("action"); Type t = this.GetType(); MethodInfo m = t.GetMethod(action); Response.Write(gjBll.getToString(m.Invoke(this, null))); Response.End(); } public string getArea() { System.Text.StringBuilder sb = new System.Text.StringBuilder(); int pageindex = gjBll.getFormInt("pageindex"); if (pageindex > 0) { DataTable dt = mseBll.GetList(150, pageindex, "", "", "select AreaName from TB_Area").Tables[2]; if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { sb.Append(",{\"name\":\"" + dr["AreaName"] + "\"}"); } if (sb.Length > 0) { return string.Format("[{0}]", sb.ToString().Substring(1)); } } } return sb.ToString(); }