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

137
Views
Tring to send formdata with xhr but it send me a empty string on server side

If make this request, server-side NodeJS shows an empty string. I also try with remove header but result same empty string result like {}. I think formData append problem. here text and files are perfectly loaded.

const xhr = new XMLHttpRequest();
//get username and pass from old url
let oldUrl = (new URL(document.location)).searchParams
let username = oldUrl.get('username')
let password = oldUrl.get('Password')

//set user and pass
let url = "/new_post_request_from_user?username=" + username + "&Password=" + password

xhr.open('POST', url, true);
xhr.onload = function () {
    let response = JSON.parse(xhr.responseText)
    console.log(response)
}

let text = document.querySelector('[name=text]').value;
let files = document.querySelector('[name=imges]').files;

let formData = new FormData();
formData.append('text',text)
formData.append('picture', files[0]);

xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.send(formData);
console.log(...formData)
return false;

Here is my html/pug code

   textarea(type="text" placeholder='Post new think' name='text' required)
   input(type="file" name='imges' required)
   input(type="submit" value="Post" id="post")

Any idea, how to solve it ?

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