-1
Hello! I need to take the value of a javascript variable, post to a php page to create a php Session variable. here I try to pass the variable js:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
var valor = "";
$(document).ready(function() {
$('input:radio[name=aviso]').click(function() {
//Executa Loop entre todas as Radio buttons com o name de valor
$('input:radio[name=aviso]').each(function() {
//Verifica qual está selecionado
if ($(this).is(':checked'))
valor = parseInt($(this).val());
})
alert(valor);
$.post( "cria_session.php", { aviso: valor} );
})
})
</script>
Here I try to at least print on the screen:
<?
echo "Olá <script>document.write(valor)</script>"?>
Only what works is Alert(value);
Does anyone know?
You will get the value in PHP with
$_POST['aviso']
– Sam
I’ve tried that. But it didn’t show anything!
– Rubens Sgarbi Ayres
It will not display anything at all, because PHP will run on the server when Ajax requests. Unless you use a callback for some purpose.
– Sam
In javascript, try to give a few
console.log(valor);
and see if the variable has any information.– Marcelo Martins
Marcelo Martins, has yes. It is being displayed correctly in Alert(value);
– Rubens Sgarbi Ayres
So... Inside the js script it’s all ok. It’s just not sending the PHP pro value!
– Rubens Sgarbi Ayres
How do you know you’re not sending?
– Sam
'Cause I’ll have it printed $_POST['warning']
– Rubens Sgarbi Ayres