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

279
Views
javascript JSON.stringify datos vacíos cuando se ven en PHP $_POST

Estoy tratando de enviar datos de formulario a través de XMLHttpRequest.send() y, en el servidor, $_POST está vacío. ¿Cuál es la sintaxis de datos y el tipo de contenido correctos que se deben usar para que $_POST reciba los datos?

Así es como construyo los datos:

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

Y,

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

espectáculos

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

El cuerpo de mi función de remitente es:

 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);

En el lado del servidor, tengo esto desde el principio en PHP:

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

Cuando regresa la respuesta, el estado es 200 y el texto de responseText es simplemente

 $_POST: Array ( )

NOTA: pregunta aclarada en la parte superior y reabierta.

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!