HTMLPage测试js通过ajax调用

HTMLPage测试js通过ajax调用接口

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript">
        var Json=json="{\r\n  \"head\": {\r\n    \"xzqdm\": \"320801\",\r\n    \"wdbs\": \"320801001\"\r\n  },\r\n  \"data\": {\r\n    \"ywbh\": \"32101412123\",\r\n    \"jdmc\": \"受理\",\r\n    \"myd\": \"2\",\r\n    \"pjsj\": \"2019-10-30 10:22:36\",\r\n    \"blry\": \"张三\",\r\n    \"sqrxm\": \"李四\",\r\n    \"sqrlxfs\": \"18888888888\"\r\n  }\r\n}";

        var XMLHttpReq;

        function createXMLHttpRequest() {
            try {
                XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); //IE高版本创建XMLHTTP
            }
            catch (E) {
                try {
                    XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); //IE低版本创建XMLHTTP
                }
                catch (E) {
                    XMLHttpReq = new XMLHttpRequest(); //兼容非IE浏览器,直接创建XMLHTTP对象
                }
            }
        }

        function sendAjaxRequest(url) {
            alert(url);
            var json;
            createXMLHttpRequest();
            XMLHttpReq.open("post", url, false);
            XMLHttpReq.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
            XMLHttpReq.onreadystatechange = function () {

            alert(XMLHttpReq.readyState+ XMLHttpReq.status);

            if (XMLHttpReq.readyState == 4) {
                    if (XMLHttpReq.status == 200) {
                       json = eval("(" + XMLHttpReq.responseText + ")");  
                   }
                }
            }
            XMLHttpReq.send(encodeURIComponent(json));
            return json;
        }
    </script>
</head>
<body>
    <input id="Button1" type="button" onclick="sendAjaxRequest('http://192.168.1.188:8080/api/v1/evaluate')" value="button" />    
</body>
</html>

 

posted @ 2019-10-31 14:14  龙骑科技  阅读(595)  评论(0编辑  收藏  举报