Web前端 测试数据接口url,如何post一个XML字符串,点击保存就可以保存到数据库

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>测试xml服务</title>
    <script src="../js/kendo/jquery.min.js"></script>
    <script src="../js/kendo/kendo.all.min.js"></script>
    <script src="../js/kendo/kendoAjax.js"></script>
</head>
<body>
    <input type="button" id="btnSave" value="提交" />

    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnSave').click(function () {
                var xmlHttp = createXMLHttp();
                if (xmlHttp == null) {
                    alert("不支持ajax");
                    return;
                } else {
                    xmlHttp.onreadystatechange = function () {
                        if (xmlHttp.readyState == 4) {
                            alert("请求完成");
                        }
                    }
                    var xmlBody = createXMLContent();
                    var url = 'http://192.168.0.88:17102/EVCENG/ICEvent';
                    xmlHttp.open('post', url, true);
                    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    alert(xmlBody);
                    xmlHttp.send(xmlBody);
                }
            });

        })
        function createXMLContent() {
            var xmlContent = '<Data><ICEvent Title="事件" EventDesc="描述" EventClass="风险" EventName="年度安排不一致" InvObj="划纲要编制" BusAction="五年规划纲要编制" RiskLevel="重大" HappenTime="2016-06-14 13:00:00" FoundTime="2016-06-15 12:00:00" HappenUnit="办公厅" ResponsibleUser="zhangchao" SourceSys="00001" LeadUnit="财政部" Response="应对措施"/></Data>';
            return xmlContent;
        }

        function createXMLHttp() {
            var httpRequest;
            try {
                httpRequest = new XMLHttpRequest();

            } catch (e) {
                try {
                    httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try {
                        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {
                        return null;
                    }
                }
            }
            return httpRequest;
        }

    </script>
</body>
</html>

  

posted @ 2016-06-15 14:35  Reyco  阅读(991)  评论(0编辑  收藏  举报