Files
java-tutorials/spring-security-mvc-socket/src/main/resources/static/ws.js
T
2019-10-24 13:20:08 +02:00

26 lines
675 B
JavaScript

var stompClient = null;
function connect() {
stompClient = Stomp.client('ws://localhost:8080/ws');
stompClient.connect({}, function (frame) {
stompClient.subscribe('/topic/greetings', function (response) {
showGreeting(JSON.parse(response.body).content);
});
});
}
function sendName() {
stompClient.send("/app/hello", {}, JSON.stringify({'name': $("#name").val()}));
}
function showGreeting(message) {
$("#greetings").append("<tr><td>" + message + "</td></tr>");
}
$(function () {
connect();
$("form").on('submit', function (e) {
e.preventDefault();
});
$( "#send" ).click(function() { sendName(); });
});