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

133
Views
How to add JSON data to GET request to XMLHttpRequest?

I have a problem with setting JSON data in a GET request. I tried: As POST request (with POST request it works)

xhr.open("GET", "http://localhost/test", true);
body = JSON.stringify({"email": "hey@mail.com", "password": "101010"});
xhr.send(body);

As query string:

var json = {"hello": "world"};
var url = "http://localhost/test?data=" + encodeURIComponent(JSON.stringify(json));
xhr.open("GET", url, true);
xhr.send();

On the backend method, req.json returns null, but I can see the query string.

Also, it works in Postman if I set JSON data to the body. On the backend, I see JSON data in the request.

P.S.: In my previous project I used the same backend framework but the frontend was based on jQuery instead of pure JS and the ajax method worked correctly.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

2 months without web development born such stupid questions. I don't use node.js but I think node.js acts so. I remembered the right way. I have tried to use "localhost?data={a: 9}" but the correct way is "localhost?a=9". The backend will parse all query variables as input in the Rest interface. Thanks to @evolutionxbox for kicking to the right side.

about 4 years ago · Juan Pablo Isaza 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!