26 lines
675 B
JavaScript
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(); });
|
|
}); |