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

175
Views
imposible pasar la variable js al código php

tengo este codigo

 function getPackage(id) { console.log(id) }
 <button onClick="getPackage('.$rRow["id"].')" type="button" data-bs-toggle="modal" data-bs-target="#exampleModalScrollable" data-bs-placement="top" onClick="myFunction();" title="Download Playlist" class="btn btn-light waves-effect waves-light btn-xs" ><i class="mdi mdi-video-switch"></i></button>

entonces, cuando hago clic en el botón, paso el valor de id a una función getPackage() y puedo ver el valor en console.log(id)

ahora tengo un código php:

 <?php $rUser = getUser("61"); ?>

mi pregunta es ¿cómo puedo pasar el valor de la variable js console.log(id) a mi código php? Necesito cambiar el número "61" por la id de la variable js, por ejemplo, así:

 <?php $rUser = getUser("id"); ?>

alguien tiene idea? gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Al escribir el código PHP y JS en el mismo archivo que usted hizo, se genera dinámicamente el código HTML/JS del lado del cliente usando PHP, la dirección es [servidor->cliente], por lo que usar este método nunca podrá enviar información del cliente al servidor. .

Tienes dos soluciones:

  1. Enviar formulario de comunicación [cliente->servidor] (involucrar la navegación de la página o abrir una nueva pestaña)
  2. AJAX (ejecutar en segundo plano, sin navegación de página involucrada)

Puede probar JQuery para facilitar el uso de JS para la opción n. ° 2

Si está usando JS puro, use esto:

 var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // Typical action to be performed when the document is ready: document.getElementById("demo").innerHTML = xhttp.responseText; } }; xhttp.open("GET", "your link", true); xhttp.send();

Si vas a usar JQuery, entonces usa esto:

 $.ajax({ url: "test.html", data: "param1=value1&param2=value2", method: "POST" // OR GET }).done(function() { // X: Code here will only run after server responded }); // Y: Code here will run first before X
about 4 years ago · Juan Pablo Isaza Report
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!