I know it must be a frequent problem and everything, but I searched in several places and could not fix my problem:
In the project I'm working on, there's a javascript function in which a variable called codigo
gets a certain value.
So when a button is clicked, the value of the codigo
variable must be passed to a PHP variable for insertion into the database.
The problem is that I can not do this transfer with the values.
Here is the part where the button is
<input type="submit" name="btnEnviar" onclick="ConfirmarAssinatura();" class="btn btn-primary btn-lg" value="Confirmar Assinatura"/>
Here's the part in Javascript:
function ConfirmarAssinatura(){
$.ajax({
url:'tela-planos.php',
type:"POST",
cache: false,
data: { 'cod': codigo },
success: function (){
alert (codigo)
},
erro: function(result){
alert('errou')
}
});
}
And here's the part of the php code where you'll do the action:
if (isset($_REQUEST['cod'])){
// executa o resto do código.
}
The problem is that it is not working. Can anyone help me?