浏览器原生AJAX请求

点击查看代码
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8" />
    <script type="text/javascript" language="javascript">

        function createXMLHttpRequest() {
                var xmlHttp;
                if (window.ActiveXObject)
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                //xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                else if (window.XMLHttpRequest)
                    xmlHttp = new XMLHttpRequest();
                return xmlHttp;
            }


        function Newton() {
                var xmlHttp = createXMLHttpRequest();
                var webFileUrl = "http://192.167.15.56:18008/api";
                xmlHttp.open("POST", webFileUrl, false);
                xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xmlHttp.send("cmd=2&speed=10&angle=0");
                //var result = ;
                if (xmlHttp.readyState == 4)
                    alert;
            }

    </script>
</head>

<body>
    <div>
        <div>
            <form id="form1" onsubmit="return false">
              <input type="submit" value="直行" onclick="Newton()" />
            </form>
        </div>
    </div>
</body>

</html>
posted @ 2023-02-08 17:54  Rain1112022  阅读(21)  评论(0)    收藏  举报