
最近要用到jquery进行异步读取数据的功能,jquery提供了许多内置的异步读取函数,给大家演示下最常用的$.ajax用法
在客户端文本框输入一个内容,然后在服务器端返回时间
在DEMO中要用到ashx文件,用于获取服务器的信息
效果图片

escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串。
客户端代码
服务器端代码
<%@ WebHandler Language="C#" Class="ContentHandler" %>
using System;
using System.Web;
public class ContentHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string output = "";
string name = context.Request.Params["name"];
output = GetJsonData(name);
context.Response.ContentType = "text/plain";
context.Response.Write(output);
}
public bool IsReusable {
get {
return false;
}
}
public string GetJsonData(string aa)
{
string result = "{name:/""+aa+"/",dt:/""+DateTime.Now.ToString()+"/"}";
return result;
}
}
完整实例代码点击此处本站下载。
希望本文所述对大家jQuery程序设计有所帮助。
