zoukankan      html  css  js  c++  java
  • 原生Ajax的怎么用?

    <script>
        function createXMLHttpRequest() {
            var xmlhttp;
            try {
                //先直接创建XMLHttpRequest
                xmlhttp = new XMLHttpRequest();
            } catch (e) {
                try {
                    //如果有异常,创建不成功
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    //如果还有异常
                    try {
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {
                        alert("您的浏览器不支持ajax");
                        return;
                    }
                }
            }
            return xmlhttp;
        }
      
    // 发送原生Ajax请求的方法
    function checkName(obj) { //得到XMLHttpRequest对象 var xmlhttp = createXMLHttpRequest();      //开启请求 xmlhttp.open("post", "${pageContext.request.contextPath}/stu/registCheck"); xmlhttp.onreadystatechange = function() { //如果响应成功 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var jsonObj = JSON.parse(xmlhttp.responseText); var span = document.getElementById("name2"); if (jsonObj.userExsit) { var input = document.getElementById("input"); input.isDisabled = "true"; span.innerHTML = "<font color='red'>" + jsonObj.msg + "</font>"; } else { span.innerHTML = "<font color='green'>" + jsonObj.msg + "</font>"; } } } //设置请求头,意思是以post的方式提交表单数据,编码格式为utf-8 xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); //发送请求 xmlhttp.send("name=" + obj); } </script>
  • 相关阅读:
    POJ 1795 DNA Laboratory
    CodeForces 303B Rectangle Puzzle II
    HDU 2197 本源串
    HDU 5965 扫雷
    POJ 3099 Go Go Gorelians
    CodeForces 762D Maximum path
    CodeForces 731C Socks
    HDU 1231 最大连续子序列
    HDU 5650 so easy
    大话接口隐私与安全 转载
  • 原文地址:https://www.cnblogs.com/JavaNeverGiveUp/p/11906377.html
Copyright © 2011-2022 走看看