zoukankan      html  css  js  c++  java
  • Ajax 经典实例

    使用POST方式的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 type="text/javascript">
    
            var xmlHttp;
            if (typeof XMLHttpRequest != "undefined") {
                xmlHttp = new XMLHttpRequest();
            } else if (window.ActiveXObject) {
                var aVersions = ["Msxml2.XMLHttp.5.0", "Msxml2.XMLHttp.4.0", "Msxml2.XMLHttp.3.0", "Msxml2.XMLHttp", "Microsoft.XMLHttp"];
                for (var i = 0; i < aVersions.length; i++) {
                    try {
                        xmlHttp = new ActiveXObject(aVersions[i]);
                        break;
                    } catch (e) { }
                }
            }
    
    
            function userAuthen() {
                var account = document.getElementById("account").value;//账户
                var pwd = document.getElementById("pwd").value;//密码
                var ip = document.getElementById("ip").value;//ip
                var port = document.getElementById("port").value;//port
    
                var jsonObj = {
                    "head": { "type": 2, "length": 0, "session": 0 }, "body": {
                        "account": account, "name": "", "password": pwd,
                        "authmode": 1, "session": 0, "role": 0, "operate": 1, "optResult": false, "errMsg": ""
                    }
                };
                var url = "http://localhost/authen";
                alert(url);
                xmlHttp.onreadystatechange = callBack;
                xmlHttp.open("post", url, true);
                xmlHttp.send(jsonObj.toString());
            }
    
            function callBack(msg) {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                    var callbackMsg = xmlHttp.responseText;
                    alert("验证结果:"+callbackMsg);
                }
            }
        </script>
    </head>
    <body style="background-color: lightblue;  80%; height: 100%;">
        <div style="text-align: center; vertical-align: middle">
            <div>  账户:<input type="text" name="account" id="account" /></div>
            <div>  密码:<input type="password" name="pwd" id="pwd" /></div>
            <div>服务器IP:<input type="text" name="ip" id="ip" /></div>
            <div>  端口:<input type="text" name="port" id="port" /></div>
            <div>
                <input type="button" value="登录" onclick="userAuthen();" />
            </div>
        </div>
    </body>
    </html>
    


     

  • 相关阅读:
    go 字符串拼接
    go中字符串的切片和索引使用
    golang 日志输出到指定位置代码
    go命令手动加载所有的安装包
    gin框架入门前后端gin-admin开源项目学习
    go container/list双向链使用实例
    使用 container/list 包 手写实现一个双向链表,将 101、102 和 103 放入其中并打印出来
    Hibernate基础增删改查语法
    Eclipse集成Hibernate操作Sqlserver实例
    sqlserver存储过程批量插入数据
  • 原文地址:https://www.cnblogs.com/liancs/p/3879268.html
Copyright © 2011-2022 走看看