You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
651 B
31 lines
651 B
const ws = new WebSocket(`ws://${window.location.host}`);
|
|
|
|
ws.onopen = () => {
|
|
console.log("Connected to server");
|
|
ws.send("Hello from client!");
|
|
};
|
|
|
|
ws.onmessage = event => {
|
|
console.log(`Message from server: ${event.data}`);
|
|
};
|
|
|
|
ws.onclose = () => {
|
|
console.log("Disconnected from server");
|
|
};
|
|
|
|
$("#submit_user_pwd").on("click", () => {
|
|
const name = $("#username").val();
|
|
const pwd = $("#password").val();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/test",
|
|
data: JSON.stringify({ name, pwd }),
|
|
contentType: "application/json",
|
|
success: res => {
|
|
console.log("Success", res);
|
|
},
|
|
error: err => {
|
|
console.error("Error", err);
|
|
},
|
|
});
|
|
});
|