• Ajax在网页中的简单应用


    苏朋老师的例子。该例子实现到www.163.com上验证一个用户是否注册。
    首先注册并得到xmlhttp对象。然后提交并得到返回值。

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

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
            <script language="javascript" type="text/jscript">
            //检测浏览器,创建xmlhttp-request对象
            function getXMLRequester()
            {
                var xmlhttp_request = false;
                try
                {
                    if(window.ActiveXObject)
                    {
                        for(var i = 5;i;i--)
                        {
                            try
                            {
                                if(i==2)
                                {
                                    xmlhttp_request = new ActiveXObject("Microsoft.XMLHTTP");
                                }
                                else
                                {
                                    xmlhttp_request = new ActiveXObject("Msxml2.XMLHTTP" +i+"0");
                                    xmlhttp_request.setRequestHeader("Content-Type","text-xml");
                                    xmlhttp_request.setRequestHeader("Content_Type","gb2312");                               
                                }
                                break;
                            }
                            catch(e)
                            {
                                xmlhttp_request=false;
                            }
                        }
                    }
                    else if(window.XMLHttpRequest)
                    {
                        xmlhttp_request = new XMLHttpRequest();
                        if(xmlhttp_request.overrideMineType)
                        {
                            xmlhttp_request.overrideMineType("text/xml");
                        }
                    }
                }
                catch(e)
                {
                    xmlhttp_request = false;
                }
                return xmlhttp_request;
            }
           
            function IDRequest(n)
            {
                url = n + document.getElementById("txtUserID").value;//定义网址参数
               
                xmlhttp_request = getXMLRequester();
                xmlhttp_request.onreadystatechange = doContents;//调用doContent函数;
                xmlhttp_request.open("Get",url,true);
               
                xmlhttp_request.send(null);
            }
           
            function doContents()
            {
                if(xmlhttp_request.readyState == 4)//收到完整的服务器响应
                {
                    if(xmlhttp_request.status == 200)//Http服务器响应ok
                        document.getElementById("message").innerHTML = xmlhttp_request.responseText;//服务器响应的值
                    else
                        alert(http_request.status);
                }
            }
           
            </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input type="text" id="txtUserID" style="font-size:12px;" />
            <input type="button" id="btnOk" value="校验" style="font-size:12px" onclick ="IDRequest('http://reg.163.com/register/checkssn.jsp?username=')" />
            <div id="message"></div>
        </div>
        </form>
    </body>
    </html>

  • 相关阅读:
    XCode编译器介绍
    iOS程序的启动过程介绍
    浅谈观察者、工厂、简单工厂设计模式
    iPhone4/4s 5.1.1版本越狱后无法连接iTunes,出现0xE8000012错误的解决方法
    【转】iOS App 自定义 URL Scheme 设计
    【转】iPhone通讯录AddressBook.framework和AddressBookUI.framework的应用
    iOS6正式版不完美越狱教程(附安装讯飞输入法)
    批处理中setlocal enabledelayedexpansion的作用
    应用审核reject理由汇总
    Hudson安装和配置
  • 原文地址:https://www.cnblogs.com/VirtualMJ/p/762382.html
Copyright © 2020-2023  润新知