无法在源上执行onmessage事件

时间:2016-08-02 08:19:48

标签: javascript java spring-boot netflix-eureka

<!DOCTYPE html>
    <html>
    <head>
    <link href="<c:url value="css/app.css" />" rel="stylesheet"
        type="text/css">
    <script type="text/javascript">

    function portHost() {
        var companyName = document.getElementById('companyName').value;
        var contains = document.getElementById('contains').value;
        var console = document.getElementById('console');
        var esControllerCall = "/esss?companyName=" + companyName + "&contains="
                + contains;

        var source = new EventSource(esControllerCall);
        //debugger;
        source.onmessage = function(event) {

                alert('in om msg');

            }
        };

    </script>
    <title>Hello World!</title>
    </head>
    <body class="security-app" onload="portHost();">
        <div class="details">

            <h2>Spring Security Testing of Kafka HBase Elasticsearch</h2>


        </div>

        <div class="lc-block">
            <h1>MSGS FROM ELASTICSEARCH</h1>


            <input name="companyName" type="hidden"
                value=<%=request.getParameter("companyName")%> id="companyName" /> <input
                name="contains" type="hidden"
                value=<%=request.getParameter("contains")%> id="contains" />

            <form action="/esjsp" method="get">
                <input type="submit" class="button red big" value="Sign Out" /> <input
                    type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
                <div id="console"
                    style="width: 400px; height: 400px; overflow-y: scroll;"></div>
            </form>
        </div>
    </body>
    </html>

我想调用返回主机名和portno的控制器。但 onmessage 事件无法执行。 我无法看到警告('在om msg'中)的警告消息; 我该怎么办 ? 出了什么问题请告诉我。 提前致谢。 任何帮助都会很明显。

0 个答案:

没有答案