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

269
Views
javascript JSON.stringify data empty when viewed in PHP $_POST

I'm trying to send form data via XMLHttpRequest.send() and, on the server, $_POST is empty. What is the correct data syntax and content-type to use so that $_POST receives the data ?

Here's how I construct the data:

var data = JSON.stringify ({
  "first-name": document.getElementById("contact-first-name").value,
  "last-name": document.getElementById("contact-last-name").value,
  ...
});

And,

console.log ("data: " + data);

shows

data: {"first-name":"peri","last-name":"hartman", ...}

My sender function body is:

var url = "php/update_member.php";
var http = new XMLHttpRequest ();
http.onload = function ()
{
  console.log ("getMemberAsync results: status + http.status);
  console.log (http.responseText);
}
http.open ("POST", url, true);
http.setRequestHeader ("Content-Type", "application/json; charset=utf-8");
http.send (data);

On the server side, I have this early on in PHP:

print '$_POST: '; print_r ($_POST);

When the response comes back, the status is 200 and the responseText is simply

$_POST: Array
(
)

NOTE: question clarified at top and reopened.

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!