Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

270
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda