js ajax 无效了
前台页面代码:程序代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="JsAjaxJiShu_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www."> <html xmlns="http://www."> <head runat="server"> <title></title> <script type="text/javascript" language="javascript"> var request; var resResule=""; function createRequest() { try { request = new XMLHttpRequest(); } catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = false; } } } if (!request) alert("Error initializing XMLHttpRequest!"); } function change(){ var user = document.getElementById("<%= username.ClientID %>").value; var url = "GetUsers.ashx?user=" + user + ""; createRequest(); request.open("get",url,true); request.onreadystatechange = function showResult() { if (request.readystate == 4) { if (request.status == 200) { resResule = request.responseText; if (resResule == "1") { message.innerHTML = username + "不能作为用户名注册"; } else { message.innerHTML = username + "可以注册"; } } } } request.send(null); } </script> </head> <body> <form id="form1" runat="server"> <div> 用户名:<asp:TextBox ID="username" runat="server" onblur="change()"></asp:TextBox><span id = "message"></span> </div> <div> 密码:<asp:TextBox ID="password" runat="server"></asp:TextBox> </div> </form> </body> </html>GetUsers.ashx 页面代码:
程序代码:
<%@ WebHandler Language="C#" Class="GetUsers" %> using System; using System.Web; public class GetUsers : IHttpHandler { public void ProcessRequest (HttpContext context) { string users = context.Request.QueryString["user"].ToString(); if (users.ToLower().Trim().IndexOf("admin") != -1) { context.Response.Write("1"); } else { context.Response.Write("2"); } } public bool IsReusable { get { return true; } } }
输入 admin后没反映。。。。