reset_pwd.js 884 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. function renderXHR_data(jsonObj) {
  2. XHRstring = ''
  3. for (const [key, value] of Object.entries(jsonObj)) {
  4. console.log(value)
  5. if (typeof (value) == "object") {
  6. XHRstring += (key+'=['+value.join(',')+']&')
  7. }
  8. else {
  9. XHRstring += (key + '=' + value + '&')
  10. }
  11. }
  12. XHRstring = XHRstring.substring(0, XHRstring.length - 1);
  13. return XHRstring
  14. }
  15. $(".sender").click(function () {
  16. var pwd = $("#in_pwd").val;
  17. var code = $("#code").val;
  18. var url = "/reset_pwd";
  19. var xhr = new XMLHttpRequest();
  20. xhr.open("POST", url);
  21. xhr.setRequestHeader("accept", "application/json");
  22. xhr.setRequestHeader("Content-Type", "application/json");
  23. xhr.onreadystatechange = function () {
  24. if (xhr.readyState === 4) {
  25. alert('重設成功')
  26. }};
  27. var dataOBJ = { "coed": code, "password": pwd}
  28. data = renderXHR_data(dataOBJ)
  29. xhr.send(data);
  30. });