-1
I know it must be a frequent problem and all, but I looked in several places and could not fix my problem:
In the project I am working on there is a javascript function in which a variable called codigo
receives a certain value.
So when a button is clicked, the value of the variable codigo
must be passed to a PHP variable for insertion in the database.
The problem is I can’t make that transfer with the values.
Here’s the part where the button is
<input type="submit" name="btnEnviar" onclick="ConfirmarAssinatura();" class="btn btn-primary btn-lg" value="Confirmar Assinatura"/>
Here is 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 is the part of php code where you will perform the action:
if (isset($_REQUEST['cod'])){
// executa o resto do código.
}
The problem is it’s not working. Can someone help me?
Where is defined
codigo
in JS? Is any warning displayed? Which? in PHP, what is the return ofvar_dump($_POST)
?– Woss
"The problem is it’s not working"... this phrase is too generic and broad. Say what is not working?
– Sam
@Andersoncarloswoss the variable
codigo
is set at the beginning in the js script. It is a global variable. Alert appears insuccess
. What I find strange, appears the Success message but does not fall in the if of PHP– Gustavo Teixeira
@dvd The above comment says what is happening
– Gustavo Teixeira
When and as the variable
codigo
is defined?– Sam