I need to send information from webside to server which i have already done with the following code,
<!DOCTYPE html>
<html>
<script>
//her definere vi varibaler
var Network = {"name":"", "password":""}
var json;
var xhr = new XMLHttpRequest();
var Json = JSON.stringify(Network)
//her definere vi en funktion, som laver pop up boxes
function Info(sp) {
let svar = prompt(sp, "skriv information her");
return svar
}
//her kopiere vi data fra pop boksene over i javascript objekt
Network.name = Info("Indtast internet navn");
Network.password = Info("Indtast internet adgangskode");
//her logger vi objektet i consolen
console.log(Network);
//her sender vi netværks navnet og netværks adgangskoden til esp'en
xhr.open("GET", "/network?Json="+Json+"}", true);
xhr.send();
</script>
</html>
This code works, but here is a problem i dont know if it is a bug or a error that causes the problem. I receive the following error on my esp8266 from the ArduinoJson library when i deserialize the Json objekt the error is IncompleteInput. The problem is clear when I look at AJAX request AJAX request. It is easy to see that the text is missing the end } which is what i believe is causing the error. The reason why i believe that is that when i manually type in something it works like a charme. The question is how do I fix it.
The solution for my problem was found in the HTML page that i showed in the post. User romkey told me to parse the string from outside the function where i open the XML object this worked immediately.This is the code that solved the problem,
<!--Her fortællers der, hvilket form for dokumnet det er-->
<!DOCTYPE html>
<html>
<script>
//her definere vi varibaler
var Network = {"name":"", "password":""}
var xhr = new XMLHttpRequest();
var Json;
var url;
//her definere vi en funktion, som laver pop up boxes
function Info(sp) {
let svar = prompt(sp, "skriv information her");
return svar
}
//her kopiere vi data fra pop boksene over i javascript objekt
Network.name = Info("Indtast internet navn");
Network.password = Info("Indtast internet adgangskode");
//her logger vi objektet i consolen
console.log(Network);
// her parser vi Netowrk objektet over i JSON (JavaScriptObjektNotation)
Json = JSON.stringify(Network)
url = "/network?Json="+Json
//her sender vi netværks navnet og netværks adgangskoden til esp'en
xhr.open("GET", url, true);
xhr.send();
</script>
</html>