JQUERY和JSON 结合

上传人:f****u 文档编号:128307047 上传时间:2020-04-20 格式:PDF 页数:9 大小:126.87KB
返回 下载 相关 举报
JQUERY和JSON 结合_第1页
第1页 / 共9页
JQUERY和JSON 结合_第2页
第2页 / 共9页
JQUERY和JSON 结合_第3页
第3页 / 共9页
JQUERY和JSON 结合_第4页
第4页 / 共9页
JQUERY和JSON 结合_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《JQUERY和JSON 结合》由会员分享,可在线阅读,更多相关《JQUERY和JSON 结合(9页珍藏版)》请在金锄头文库上搜索。

1、通过 AJAX 异步减少网络内容传输 而 JSON 则可以把传输内容缩减到纯数据 然 后利用 jQuery 内置的 AJAX 功能直接获得 JSON 格式的数据 在客户端直接绑定到数据 控件里面 从而达到最优 1 设计 htm 页面 1 2 3 4 test2 5 6 7 8 9 10 11 12 13 input id first type button value input id previous type button 14 value 16 17 18 19 20 订单 ID 21 22 23 客户 ID 24 25 26 雇员 ID 27 28 29 订购日期 30 31 32 发

2、货日期 33 34 35 货主名称 36 37 38 货主地址 39 40 41 货主城市 42 43 44 更多信息 45 46 47 48 49 50 LOADING 51 52 53 54 55 注 ID 属性比较重要 用于数据绑定 2 使用 jQuery 编写 AJAX 请求文件 1 var pageIndex 1 2 var pageCount 0 3 4 function 5 GetPageCount 取得分页总数 6 pageCount parseInt pagecount val 分页总数放到变量 pageCount 里 7 load hide 隐藏 loading 提示 8

3、template hide 隐藏模板 9 ChangeState 0 1 设置翻页按钮的初始状态 10 11 bind 绑定第一页的数据 12 13 第一页按钮 click 事件 14 first click function 15 pageIndex 1 16 ChangeState 0 1 17 bind 18 19 20 上一页按钮 click 事件 21 previous click function 22 pageIndex 1 23 ChangeState 1 1 24 if pageIndex pageCount 37 38 pageIndex pageCount 39 Chan

4、geState 1 0 40 41 bind pageIndex 42 43 44 最后一页按钮 click 事件 45 last click function 46 pageIndex pageCount 47 ChangeState 1 0 48 bind pageIndex 49 50 51 52 AJAX 方法取得数据并显示到页面上 53 function bind 54 55 id ready remove 56 load show 57 ajax 58 type get 使用 get 方法访问后台 59 dataType json 返回 json 格式的数据 60 url Hand

5、ler ashx 要访问的后台地址 61 data pageIndex pageIndex 要发送的数据 plete function load hide AJAX 请求完成时隐藏 loading 提示 63 success function msg msg 为返回的数据 在这里做数据绑定 64 var data msg table 65 each data function i n 66 var row template clone 67 row find OrderID text n OrderID 68 row find CustomerID text n CustomerID 69 r

6、ow find EmployeeID text n EmployeeID 70 row find OrderDate text ChangeDate n OrderDate 71 if n RequiredDate undefined row find ShippedDate text Chan geDate n RequiredDate 72 row find ShippedName text n ShipName 73 row find ShippedAddress text n ShipAddress 74 row find ShippedCity text n ShipCity 75

7、row find more html More 76 row attr id ready 改变绑定好数据的行的 id 77 row appendTo datas 添加到模板的容器中 78 79 id ready show 80 SetPageInfo 81 82 83 84 85 function ChangeDate date 86 87 return date replace replace 88 89 90 设置第几页 共几页的信息 91 function SetPageInfo 92 93 pageinfo html pageIndex pageCount 94 95 96 AJAX

8、方法取得分页总数 97 function GetPageCount 98 99 ajax 100 type get 101 dataType text 102 url Handler ashx 103 data getPageCount 1 104 async false 105 success function msg 106 pagecount val msg 107 108 109 110 111 改变翻页按钮状态 112 function ChangeState state1 state2 113 114 if state1 1 115 116 document getElementB

9、yId first disabled 117 document getElementById previous disabled 118 119 else if state1 0 120 121 document getElementById first disabled disabled 122 document getElementById previous disabled disabled 123 124 if state2 1 125 126 document getElementById next disabled 127 document getElementById last

10、disabled 128 129 else if state2 0 130 131 document getElementById next disabled disabled 132 document getElementById last disabled disabled 133 134 3 利用 JSON 三方控件在服务器端获取 JSON 格式数据 1 2 3 using System 4 using System Data 5 using System Web 6 using System Collections 7 using System Web Services 8 using

11、 System Web Services Protocols 9 using System Configuration 10 using System Data SqlClient 11 using System Text 12 using System Xml 13 using NetServ Net Json 14 15 namespace jQueryJSON 16 17 18 codebehindclassname 的摘要说明 19 20 WebService Namespace http tempuri org json 21 WebServiceBinding ConformsTo

12、 WsiProfiles BasicProfile1 1 22 public class Handler IHttpHandler 23 24 readonly int PageSize int Parse ConfigurationManager AppSettings PageSize 25 public void ProcessRequest HttpContext context 26 27 context Response ContentType text plain 28 不让浏览器缓存 29 context Response Buffer true 30 context Resp

13、onse ExpiresAbsolute DateTime Now AddDays 1 31 context Response AddHeader pragma no cache 32 context Response AddHeader cache control 33 context Response CacheControl no cache 34 35 string result 36 if context Request Params getPageCount null result GetPag eCount 37 if context Request Params pageInd

14、ex null 38 39 string pageindex context Request Params pageIndex 40 if context Cache Get pageindex null 41 result context Cache Get pageindex ToString 42 else 43 44 result GetPageData context Request Params pageIndex 45 context Cache Add 46 pageindex 47 result 48 null 49 DateTime Now AddMinutes 1 50

15、System Web Caching Cache NoSlidingExpiration 51 System Web Caching CacheItemPriority Default 52 null 53 54 result GetPageData context Request Params pageIndex 55 56 context Response Write result 57 58 59 private string GetPageData string p 60 61 int PageIndex int Parse p 62 string sql 63 if PageInde

16、x 1 64 sql select top PageSize ToString from Orders order b y OrderID desc 65 else 66 sql select top PageSize ToString from Orders where O rderID not in select top PageIndex 1 PageSize ToString OrderID from Orders order by OrderID desc order by OrderID des c 67 string dbfile ConfigurationManager ConnectionStrings conn ToSt ring 68 SqlConnection conn new SqlConnection dbfile 69 SqlDataAdapter da new SqlDataAdapter sql conn 70 DataTable dt new DataTable table 71 da Fill dt 72 return DataTableJson

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号