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.
 
 
 
 
 
 

39 lines
1.1 KiB

var myForm = document.getElementById('myForm')
myForm.addEventListener('submit', function(e) {
e.preventDefault();
//var data = JSON.stringify(formData(myForm));
loadJSON(formData(myForm))
})
function formData(form) {
let el = form.querySelectorAll('input[type="text"]');
let ballast = document.getElementById('myBallasts').value;
let myData = '';
myData += 'ballast' + '=' + ballast + '&';
for (var x = 0; x < el.length; x++) {
let name = el[x].name;
let value = el[x].value;
//myData[name] = value;
myData += name + '=' + value + '&'
}
return myData.slice(0, -1);
}
function loadJSON(data) {
const url = '/settings.html';
console.log(data)
const myData = data
fetch(url, {
method: 'post',
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
body: myData
})
// .then(function (response) {
// return response.json()
// }).then(function (data) {
// console.log(data)
// })
.catch(error => console.log(error))
}