Pass a Javascript variable to a php file as a variable other than php

0

How could this variable be passed to php, since I need it to make sql queries to a server.

Resolved

I sent via the fetch api, with POST the variable:

fetch('./php/views/certificacion_afiliacion_trabajador.php', {
                        method: 'POST',
                        body : JSON.stringify({'cedula': cedu}),
                    }).then(res => res.json())
                }).then(data => {
                    console.log(data);
                });

Php did not receive the data, with $ _POST, so I used this command to receive it

print_r(json_decode(file_get_contents("php://input")));

Thank you very much for your answers, they helped me to solve my doubt

    
asked by Marteen Munevar 03.11.2018 в 02:51
source

1 answer

0

You can send this variable via ajax or using axios, I give you an example:

you have your variable of js

var cedula = snapshop.val().cedula;

and then from there you send the request to the server:

axios.post(url, cedula).then( (res) => { console.log(res) }

You get a reply only so you will receive it in php and apply your query.

    
answered by 03.11.2018 / 03:10
source