index.html 1.2 KB

12345678910111213141516171819202122232425262728293031
  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. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>demo</title>
  8. </head>
  9. <body>
  10. <input type="email" placeholder="邮箱" name="email" id="emailer">
  11. <input type="text" placeholder="信息" name="message" id="messager">
  12. <input type="button" value="发送" onclick="loadDoc()">
  13. <div id="State"></div>
  14. </body>
  15. <script>
  16. function loadDoc() {
  17. var xhttp = new XMLHttpRequest();
  18. xhttp.onreadystatechange = function() {
  19. if (this.readyState == 4 && this.status == 200) {
  20. document.querySelectorAll('#State')[0].innerHTML = '发送成功'
  21. }else if (this.status == 201) {
  22. document.querySelectorAll('#State')[0].innerHTML = '服务器出错'
  23. }
  24. };
  25. xhttp.open("POST", "http://short.1473.cn/postemail", true);
  26. xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  27. xhttp.withCredentials = true;
  28. xhttp.send(`useremail=${document.querySelectorAll('#emailer')[0].value}&usermessage=${document.querySelectorAll('#messager')[0].value}`);
  29. }
  30. </script>
  31. </html>