send config as JSON

This commit is contained in:
Christian Herzog
2019-10-04 18:43:56 +02:00
parent 7629009084
commit 2f8d5759f4

View File

@@ -175,14 +175,16 @@ $(document).ready(function(){
}); });
$("input#autoexec-cb").on("click", function() { $("input#autoexec-cb").on("click", function() {
var data = { 'timestamp': Date.now() };
autoexec = (this.checked)?1:0; autoexec = (this.checked)?1:0;
data['autoexec'] = autoexec;
$.ajax({ $.ajax({
url: '/config.json', url: '/config.json',
dataType: 'json', dataType: 'json',
method: 'POST', method: 'POST',
cache: false, cache: false,
headers: { "X-Custom-autoexec": autoexec }, headers: { "X-Custom-autoexec": autoexec },
data: { 'timestamp': Date.now() }, data: data,
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
@@ -206,7 +208,9 @@ $(document).ready(function(){
}); });
$("input#save-autoexec1").on("click", function() { $("input#save-autoexec1").on("click", function() {
var data = { 'timestamp': Date.now() };
autoexec1 = $("#autoexec1").val(); autoexec1 = $("#autoexec1").val();
data['autoexec1'] = autoexec1;
$.ajax({ $.ajax({
url: '/config.json', url: '/config.json',
@@ -214,7 +218,7 @@ $(document).ready(function(){
method: 'POST', method: 'POST',
cache: false, cache: false,
headers: { "X-Custom-autoexec1": autoexec1 }, headers: { "X-Custom-autoexec1": autoexec1 },
data: { 'timestamp': Date.now() }, data: data,
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
@@ -225,12 +229,14 @@ $(document).ready(function(){
}); });
$("input#save-gpio").on("click", function() { $("input#save-gpio").on("click", function() {
var data = { 'timestamp': Date.now() };
var headers = {}; var headers = {};
$("input.gpio").each(function() { $("input.gpio").each(function() {
var id = $(this)[0].id; var id = $(this)[0].id;
var pin = $(this).val(); var pin = $(this).val();
if (pin != '') { if (pin != '') {
headers["X-Custom-"+id] = pin; headers["X-Custom-"+id] = pin;
data[id] = pin;
} }
}); });
$.ajax({ $.ajax({
@@ -239,7 +245,7 @@ $(document).ready(function(){
method: 'POST', method: 'POST',
cache: false, cache: false,
headers: headers, headers: headers,
data: { 'timestamp': Date.now() }, data: data,
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
@@ -251,17 +257,20 @@ $(document).ready(function(){
$("#save-nvs").on("click", function() { $("#save-nvs").on("click", function() {
var headers = {}; var headers = {};
var data = { 'timestamp': Date.now() };
$("input.nvs").each(function() { $("input.nvs").each(function() {
var key = $(this)[0].id; var key = $(this)[0].id;
var val = $(this).val(); var val = $(this).val();
if (key != '') { if (key != '') {
headers["X-Custom-"+key] = val; headers["X-Custom-"+key] = val;
data[key] = val;
} }
}); });
var key = $("#nvs-new-key").val(); var key = $("#nvs-new-key").val();
var val = $("#nvs-new-value").val(); var val = $("#nvs-new-value").val();
if (key != '') { if (key != '') {
headers["X-Custom-"+key] = val; headers["X-Custom-"+key] = val;
data[key] = val;
} }
$.ajax({ $.ajax({
url: '/config.json', url: '/config.json',
@@ -269,7 +278,7 @@ $(document).ready(function(){
method: 'POST', method: 'POST',
cache: false, cache: false,
headers: headers, headers: headers,
data: { 'timestamp': Date.now() }, data: data,
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);
@@ -280,16 +289,18 @@ $(document).ready(function(){
}); });
$("#flash").on("click", function() { $("#flash").on("click", function() {
var data = { 'timestamp': Date.now() };
if (blockFlashButton) return; if (blockFlashButton) return;
blockFlashButton = true; blockFlashButton = true;
var url = $("#fwurl").val(); var url = $("#fwurl").val();
data['fwurl'] = url;
$.ajax({ $.ajax({
url: '/config.json', url: '/config.json',
dataType: 'json', dataType: 'json',
method: 'POST', method: 'POST',
cache: false, cache: false,
headers: { "X-Custom-fwurl": url }, headers: { "X-Custom-fwurl": url },
data: { 'timestamp': Date.now() }, data: data,
error: function (xhr, ajaxOptions, thrownError) { error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status); console.log(xhr.status);
console.log(thrownError); console.log(thrownError);