标题:js ajax 无效了
取消只看楼主
等待冰柠檬
Rank: 2
来 自:浙江温州
等 级:论坛游民
帖 子:208
专家分:70
注 册:2008-6-25
结帖率:66.67%
已结贴  问题点数:10 回复次数:0 
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后没反映。。。。


搜索更多相关主题的帖子: ajax 
2010-09-08 14:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-319569-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021991 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved