• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

117
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.

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error