Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
How to pass JavaScript variable into a PHP function parameter?

I am trying to get a response from a Twilio API where I am facing complexity. I have a javascript variable called sid which is containing a string value.

var sid = value['sid']; // 'CA519c6aefde211131f2f44370d67607d4'

Now I need to call this variable into a PHP function as a parameter.

<?php echo $twilio->check_disputed($parameter) ?>

So, the $parameter is coming from the Javascript var sid.

I want to place the javascript variable as the parameter.

Thanks <3

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In a very simple form/example you simply need to send an http request ( here done using the Fetch api ) to your PHP script and intercept that request. The following sends a POST request with a single parameter sid which is then passed to the Twilio method as per your requirement.

<?php
    if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['sid'] ) ){
        $sid=$_POST['sid'];
        exit( $twilio->check_disputed( $sid ) );
    }
?>
<!DOCTYPE html>
<html lang='en'>
    <head>
        <meta charset='utf-8' />
        <title>Your page</title>
    </head>
    <body>
        <h1>Do lots of things...</h1>
        
        <script>
            /*
                do whatever it is you do to create your variable sid
                - here it is explicitly declared rather than derived.
            */
            const sid='CA519c6aefde211131f2f44370d67607d4';
            
            let fd=new FormData();
                fd.set('sid',sid);
                
            fetch( location.href, { method:'post', body:fd } )
                .then(r=>r.text())
                .then(data=>{
                    alert(data)
                })
        </script>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use Asynchronious request to achive that. first import your jquery library

  var actual_url = "yourDomain/data=" + data_you_want_to_pass;
  $.ajax({
            url: actual_url,
            type: 'GET',
            dataType: 'text', // added data type
            success: function(res) {
                //log if you have any response
                console.log(res);
            }
        });

now you can recieve the data on your php file using GET method.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda