The esp8266 portion of the project
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.

38 lines
1.1 KiB

  1. var myForm = document.getElementById('myForm')
  2. myForm.addEventListener('submit', function(e) {
  3. e.preventDefault();
  4. //var data = JSON.stringify(formData(myForm));
  5. loadJSON(formData(myForm))
  6. })
  7. function formData(form) {
  8. let el = form.querySelectorAll('input[type="text"]');
  9. let ballast = document.getElementById('myBallasts').value;
  10. let myData = '';
  11. myData += 'ballast' + '=' + ballast + '&';
  12. for (var x = 0; x < el.length; x++) {
  13. let name = el[x].name;
  14. let value = el[x].value;
  15. //myData[name] = value;
  16. myData += name + '=' + value + '&'
  17. }
  18. return myData.slice(0, -1);
  19. }
  20. function loadJSON(data) {
  21. const url = '/settings.html';
  22. console.log(data)
  23. const myData = data
  24. fetch(url, {
  25. method: 'post',
  26. headers: {
  27. "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
  28. },
  29. body: myData
  30. })
  31. // .then(function (response) {
  32. // return response.json()
  33. // }).then(function (data) {
  34. // console.log(data)
  35. // })
  36. .catch(error => console.log(error))
  37. }