test.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <form
  10. action=""
  11. style="display: flex; flex-direction: column; width: 200px; gap: 10px"
  12. >
  13. <input type="text" name="username" placeholder="Username" />
  14. <input type="password" name="password" placeholder="Password" />
  15. <input type="text" name="captcha" placeholder="Captcha" />
  16. <img
  17. src="https://api.danjiwanjia.com/admin/getAdminCaptchaImage"
  18. alt="Captcha"
  19. />
  20. <button type="submit">Submit</button>
  21. </form>
  22. </body>
  23. <script>
  24. const form = document.querySelector("form");
  25. form.addEventListener("submit", async (e) => {
  26. e.preventDefault();
  27. const formData = new FormData(form);
  28. const data = Object.fromEntries(formData.entries());
  29. console.log(data);
  30. const res = await fetch("https://api.danjiwanjia.com/admin/login", {
  31. method: "POST",
  32. headers: {
  33. "Content-Type": "application/json",
  34. },
  35. body: JSON.stringify(data),
  36. });
  37. const result = await res.json();
  38. console.log(result);
  39. });
  40. </script>
  41. </html>