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
Procesar una solicitud POST con PHP desde una búsqueda JS

Tengo una casilla de verificación de entrada diseñada como un interruptor ingrese la descripción de la imagen aquí

 <input id="Kim1043" class="form-check-input" onclick="toggleStatus(this) type="checkbox" name="Kim1043"> <label id="user-status-toggle" for="Kim1043"> $value['status'] </label>

donde $value['status'] existe en dos estados: Active e Inactive , información proveniente de una base de datos.

Estoy tratando de obtener una solicitud POST con JavaScript para que cuando cambie el interruptor, la base de datos se actualice con el estado actual del interruptor. Tengo una función de PHP que actualizaría la base de datos.

 function toggleStatus(radio) { var toggle = document.getElementById('user-status-toggle'); if (radio.checked) { fetch("/dashboard?php=salespeople-tb", { method: "POST", body: JSON.stringify({ status: "Active" }) }) .then((resp)) => { toggle.textContent = "Active" }) .catch((resp) => { toggle.textContent = "Error" }) } else { fetch("/dashboard?php=salespeople-tb", { method: "POST", body: JSON.stringify({ status: "Inactive" }) }) .then((resp)) => { toggle.textContent = "Inactive" }) .catch((resp) => { toggle.textContent = "Error" }) }

Entonces, este es el código PHP :

 if ($_SERVER["REQUEST_METHOD"] == "POST") { $js_response = $_POST["Kim1043"]; return $js_response; }

No sé por qué no funciona.

TL; DR Estoy tratando de ejecutar una función de PHP cuando el interruptor está activado.

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!