广博吧

位置:首页 > 职场知识 > 电脑培训

通过JQuery的Ajax调用一般处理程序

前言:

通过JQuery的Ajax调用一般处理程序

本示例大概功能是前台通过JQuery的调用一般处理程序(Handler),获取表格需要显示的信息,然后转换成json格式返回给前台,前台获取到数据后循环构建表格的行,最好把行附加到表里。

目标:

a 熟悉简单JQuery Ajax的使用

b 了解如何构造基本的Json格式的数据(构建Json也可以通过第三方的dll)

c 熟悉下handler的基本用法

1 简单效果图

2 前台代码

<%@ page="" language="C#" autoeventwireup="true" codefile="" inherits="JQueryTest_DialogAjax">

3 Handler代码

<%@ webhandler="" language="C#" class="TestHandler">using System;using ;using ric;using ;using DataDAL;using DataEnity;public class TestHandler : IHttpHandler { HttpRequest Request; HttpResponse Response; public void ProcessRequest (HttpContext context) { //不让浏览器缓存 er = true; resAbsolute = ays(-1); eader("pragma", "no-cache"); eader("cache-control", ""); eControl = "no-cache"; entType = "text/plain"; Request = est; Response = onse; string method = Request["Method"]ring(); odInfo methodInfo = ype()ethod(method); ke(this, null); } public void GetModuleInfo() { StringBuilder sb = new StringBuilder(); string jsonData = y; ListlsModule = oduleList(); nd("{"Module":["); for (int i = 0; i < t; i++) { jsonData = "{"ModuleNum":" + """ + lsModule[i]leNum + """ + ","ModuleName":" + """ + lsModule[i]leName + """ + ","ModuleDes":" + """ + lsModule[i]leDes + """ + "},"; nd(jsonData); } if (t > 0) sb = ve(th - 1, 1); nd("]}"); e(sb); } public bool IsReusable { get { return false; } }}

以上代码超简单吧,JQuery Ajax动态生成Table表格的内容就全部完成了,希望对大家有所帮助。