Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
Javascript ajax problem which makes the URL unreadable on the server side

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.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda