石墨消解 mock
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

5 months ago
  1. const ws = new WebSocket(`ws://${window.location.host}`);
  2. ws.onopen = () => {
  3. console.log("Connected to server");
  4. ws.send("Hello from client!");
  5. };
  6. ws.onmessage = event => {
  7. console.log(`Message from server: ${event.data}`);
  8. };
  9. ws.onclose = () => {
  10. console.log("Disconnected from server");
  11. };
  12. $("#submit_user_pwd").on("click", () => {
  13. const name = $("#username").val();
  14. const pwd = $("#password").val();
  15. $.ajax({
  16. type: "POST",
  17. url: "/test",
  18. data: JSON.stringify({ name, pwd }),
  19. contentType: "application/json",
  20. success: res => {
  21. console.log("Success", res);
  22. },
  23. error: err => {
  24. console.error("Error", err);
  25. },
  26. });
  27. });