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

150
Views
No se puede analizar JSON enviado a través de Javascript XMLHttpRequest en el controlador de formulario PHP

Lógica Javascript:

 const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ if (xhr.status == 200){ console.log('xhr.readyState: ' + xhr.readyState); console.log('xhr.status: ' + xhr.status); console.log('xhr.responseText: ' + xhr.responseText); alert("Thank you for connecting with me, " + $firstName + ". I'll be in touch soon via email to " + $email + "."); document.getElementById('contact_form').reset(); enableSubmitButton(); } if(xhr.status != 200){ console.log('xhr.status: ' + xhr.status); alert('Apologies, ' + $firstName + ', there was an error sending your message.'); } } }; // build JSON for form handler const prospect = { first_name: $firstName, last_name: $lastName, email: $email, project_description: $projectDescription }; const prospectJson = JSON.stringify(prospect); // console.log(prospectJson); xhr.open('get', 'inc/contact_form_handler.php?data=' + prospectJson, false); xhr.send();

Salida de la consola posterior al envío del formulario HTML y XMLHttpRequest:

 xhr.readyState: 4 xhr.status: 200 xhr.responseText: Array ( [data] => {"first_name":"FirstNameTest","last_name":"LastNameTest","email":"test@test.com","project_description":"This is my example project description."} )

El problema es que todos los valores de las variables de PHP están vacíos siguiendo la siguiente lógica:

 /* get form data JSON */ $prospectArray = $_GET; print_r($prospectArray); $arr = json_decode($prospectArray, true); // assign values to local vars based on json values $firstName = $arr["first_name"]; $lastName = $arr["last_name"]; $email = $arr["email"]; $projectDescription = $arr["project_description"];

Cualquier orientación, idea o solución es muy apreciada, gracias.

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!