通過JQuery的Ajax呼叫一般處理程式

才智咖 人氣:3.82K

前言:

通過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表格的內容就全部完成了,希望對大家有所幫助。