Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!