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"); }; $("#moveArm").on("click", () => { const x = $("#armX").val(); const y = $("#armY").val(); const z = $("#armZ").val(); $.ajax({ type: "POST", url: "/api/debug/railArm", data: JSON.stringify({ x: +x, y: +y, z: +z }), contentType: "application/json", success: res => { console.log("Success", res); }, error: err => { console.error("Error", err); }, }); });