Google Chrome中的responseText为空

时间:2017-11-06 12:22:53

标签: javascript google-chrome internet-explorer firefox xmlhttprequest

以下代码在Internet Explorer中运行良好,但在FireFox和Chrome中,responseText为空。

<!DOCTYPE html>
<html>
    <head>
        <title>Untitled</title>
        <script type="text/javascript" language="javascript">
            function UserAction() {
                var httpReq = new XMLHttpRequest();

                httpReq.open("POST", "http://tomcat/security-proxy/reporting-service-v1/reporting-service/api/v1/reporting/rapportelement/155363/16/7?referentie=G.7.0&nocache=false", true);
                httpReq.setRequestHeader("Accept", "application/xml");
                httpReq.setRequestHeader("Content-Type", "application/json");
                httpReq.setRequestHeader("X-Auth-Token", "eyJxxxxxxxxxxxxxxxxxN3iDWV2VMVM8B969YjhP1LiXI");     
                httpReq.send();

                var DateInService = httpReq.responseText;
                alert("Date: " + DateInService);
                document.body.innerHTML += "You work here from: " + DateInService.substring(3, 5) + "/" + DateInService.substring(0, 2) + "/20" + DateInService.substring(6, 8);     
            }
        </script>
    </head>
    <body>
       <button type="submit" onclick="UserAction()">Search</button>
    </body>
</html>

为什么Internet Explorer显示正确的DateInService并且Chrome和FF中仍然为空?

0 个答案:

没有答案