Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda