Spring 4 Websocket - Nothing happens

时光怂恿深爱的人放手 提交于 2019-12-04 12:58:40

Change connect function

from:

function connect() {
        var socket = new SockJS("<c:url value='/hello'/>");
        stompClient = Stomp.over(socket);
        stompClient.connect('', '', function(frame) {
            setConnected(true);
            console.log('Connected: ' + frame);
            stompClient.subscribe("<c:url value='/topic/greetings'/>", function(greeting){
                showGreeting(JSON.parse(greeting.body).content);
            });
        });
    }

To:

function connect() {
        var socket = new SockJS("<c:url value='/hello'/>");
        stompClient = Stomp.over(socket);
        stompClient.connect('', '', function(frame) {
            setConnected(true);
            console.log('Connected: ' + frame);
            stompClient.subscribe('/topic/greetings', function(greeting){
                showGreeting(JSON.parse(greeting.body).content);
            });
        });
    }

and similarly for sendName()

From:

function sendName() {
        var name = document.getElementById('name').value;
        stompClient.send("<c:url value='/app/hello'/>", {}, JSON.stringify({ 'name': name }));
    }

To:

function sendName() {
        var name = document.getElementById('name').value;
        stompClient.send('/app/hello', {}, JSON.stringify({ 'name': name }));
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!