|
|
@@ -23,7 +23,7 @@ portal = new function(){
|
|
|
progress_bar.classList.add("progress-bar-animated")
|
|
|
progress_bar.classList.remove("bg-success")
|
|
|
progress_bar.classList.remove("bg-danger")
|
|
|
- const response = await fetch(url, {
|
|
|
+ const req = fetch(url, {
|
|
|
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
|
mode: 'cors', // no-cors, *cors, same-origin
|
|
|
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
|
|
|
@@ -36,19 +36,50 @@ portal = new function(){
|
|
|
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
|
|
|
body: JSON.stringify(data) // body data type must match "Content-Type" header
|
|
|
});
|
|
|
- progress_bar.classList.remove("progress-bar-striped")
|
|
|
- progress_bar.classList.remove("progress-bar-animated")
|
|
|
- resp = await response.json(); // parses JSON response into native JavaScript objects
|
|
|
- if (resp["ok"]){
|
|
|
- error_box.innerText = "";
|
|
|
- progress_bar.classList.add("bg-success")
|
|
|
- } else {
|
|
|
+ try {
|
|
|
+ const response = await req;
|
|
|
+ var resp = await response.json(); // parses JSON response into native JavaScript objects
|
|
|
+ if (resp["ok"]){
|
|
|
+ error_box.innerText = "";
|
|
|
+ progress_bar.classList.add("bg-success")
|
|
|
+ } else {
|
|
|
+ progress_bar.classList.add("bg-danger")
|
|
|
+ error_box.innerText = JSON.stringify(resp, null, 2);
|
|
|
+ }
|
|
|
+ } catch(err){
|
|
|
+ console.error(err);
|
|
|
progress_bar.classList.add("bg-danger")
|
|
|
+ resp = {
|
|
|
+ "ok": false,
|
|
|
+ "err": err,
|
|
|
+ };
|
|
|
error_box.innerText = JSON.stringify(resp, null, 2);
|
|
|
}
|
|
|
+ progress_bar.classList.remove("progress-bar-striped")
|
|
|
+ progress_bar.classList.remove("progress-bar-animated")
|
|
|
return resp;
|
|
|
}
|
|
|
function getId(id){
|
|
|
return document.getElementById(id);
|
|
|
}
|
|
|
+ function validate_input(){
|
|
|
+ if (
|
|
|
+ getId("input_ssid").value == "" ||
|
|
|
+ getId("input_pw").value == ""
|
|
|
+ ){
|
|
|
+ getId("wifi_button").disabled = true;
|
|
|
+ } else {
|
|
|
+ getId("wifi_button").disabled = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ window.addEventListener("load",async ()=>{
|
|
|
+ getId("input_ssid").addEventListener("input",validate_input)
|
|
|
+ getId("input_pw").addEventListener("input",validate_input);
|
|
|
+ validate_input();
|
|
|
+ const resp = await postData("", {
|
|
|
+ "index_data":true
|
|
|
+ })
|
|
|
+ getId("input_ssid").value = resp["ssid"];
|
|
|
+ getId("input_pw").value = resp["pw"];
|
|
|
+ });
|
|
|
}();
|