zoukankan      html  css  js  c++  java
  • ajax 或 js 异步判断用户名是否存在

    html代码如下:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="check.aspx.cs" Inherits="check" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>js 异步判断用户名是否已被注册</title>
        <script language="javascript" type="text/javascript">
    //生成Http请求对象,用于客户端向服务/端发送异步的http请求
    function getHttpObject()
    {
        var _http;
        var browser = navigator.appName;
        if(browser == "Microsoft Internet Explorer")
        {
            //如果用户使用IE,就返回XMLHTTP的ActiveX对象
            _http = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        else//非IE
        {
            //否则返回一个XMLHttpRequest对象
            _http = new XMLHttpRequest();
        }
        return _http;
    }
    //获取全局的HTTP请求对象
    var http = getHttpObject();//也可以在顶端声明
    //处理请求状态变化
    function getHello()
    {
        //4表示请求已完成
        if (http.readyState == 4) //这里的http是全局变量
        {
            //获取服务段的响应文本
            var helloStr = http.responseText;
            //alert(helloStr);
            if(helloStr.charAt(0)!="0")//表示已经存在
                {document.getElementById("showmessage").innerHTML="浙江企业网用户名已经存在";}
            else//没有存在
                {document.getElementById("showmessage").innerHTML="浙江企业网用户名不存在";}
        }
    }
    function CheckUserName()
    {
        if(document.getElementById("Text1").value!="")
        {
            var url = "Default2.aspx?id="+document.getElementById("Text1").value;

            //指定服务端的地址
            http.open("GET", url, true);
            //请求状态变化时的处理函数
            http.onreadystatechange = getHello;
            //发送请求
            http.send(null);
        }
        else
        {
             document.getElementById("showmessage").innerHTML="请输入浙江企业网用户名";
        }
    }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
          <div>
            <input id="Text1" style=" 116px" type="text" onblur="CheckUserName()" />
          </div>
          <div id="showmessage" style="color:Red; padding-top:5px;"></div>
        </form>
    </body>
    </html>

    cs代码如下:

    protected void Page_Load(object sender, EventArgs e)
        {
             if (Request["id"] != null)
            {
                this.Response.Clear();
                if (Request["id"] == "浙江企业网")
                { Response.Write("1"); }
                else
                { Response.Write("0"); }
                this.Response.End();
            }
        }

    玉环人才吧 玉环人才网 玉环人力网 玉环招聘网 三支脚人才网

    玉环人力网(又名玉环人才网)是玉环人才吧旗下一流的玉环人力资源招聘行业服务品牌,汇集海量玉环人才,开放玉环人才简历和玉环岗位,提供玉环招聘网,玉环人才市场动态行情,玉环劳务派遣,玉环培训等,是玉环最大的人才网站。

  • 相关阅读:
    Layui的一些心得
    Oracle工具PLSQL
    .NET开发中 springMVC+NHibernate注入失败的几个常见错误
    配置好运行后Error creating context 'spring.root': Could not load type from string value
    css样式添加错误导致烦扰
    Oracle时间与系统不同步,TimeStampService
    前端入门10-JavaScript语法之对象
    前端入门9-JavaScript语法之运算符
    前端入门8-JavaScript语法之数据类型和变量
    前端入门7-JavaScript语法之相关术语
  • 原文地址:https://www.cnblogs.com/taizhouxiaoba/p/1368047.html
Copyright © 2011-2022 走看看