ajax 第一节
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="js/jquery-1.8.2.min.js"></script> <script type="text/javascript"> $(function () { $("#btn").click( function () { if (XMLHttpRequest) { var xhr = new XMLHttpRequest(); } else { //ie 5 6
xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("get", "handler1.ashx?r=1", true); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { $("#test1").val(xhr.responseText); } } } } ) }) </script> </head> <body> <input type="button" id="btn" value="ajax"/> <input type="text" id="test1" value="3" /> </body> </html>
一般处理程序 页 :
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication2 { /// <summary> /// Handler1 的摘要说明 /// </summary> public class Handler1 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write(DateTime.Now.Millisecond); } public bool IsReusable { get { return false; } } } }