</div>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/23740548/how-do-i-pass-variables-and-data-from-php-to-javascript" dir="ltr">How do I pass variables and data from PHP to JavaScript?</a>
<span class="question-originals-answer-count">
(20 answers)
</span>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2020-01-06 21:49:57Z" class="relativetime">4 months ago</span>.</div>
</div>
</aside>
This is translated, I'm sorry if there's something wrong.
I have a problem and it is that when I insert the name of the session it tells me that it is undefined. I did tests inserting the manual username and if everything works.
<? php
session_start ();
echo var_dump ($ _SESSION);
?>
The first thing that the php has is this, as you can see the var_dump correctly shows the user's name.
The message of (username) is not defined in the console.
I'm doing it with a modal.
The textbox is inserted correctly, I just need the name of the session that inserts it. The database works correctly (I tried inserting the parameters manually)
As you can see with var_dump correctly shows the user name of the session. Also insert the content of textarea well, just need to insert the name of the session
<script>
$(inicializarEventos);
function inicializarEventos(){
$("#insertar").click(insertarSugerencia);
}
function insertarSugerencia(){
var nombreUsuario= <?php echo $_SESSION['usuario']?>;
var textoSugerencia=$("#textoSugerencia").val();
console.log(nombreUsuario,textoSugerencia);
$.ajax({
url:"bd/bd.php",
method: "POST",
data:{nombreUsuario:nombreUsuario,textoSugerencia:textoSugerencia},
dataType:"JSON",
success:function(){
alert ("Sugerencia enviada correctamente");
$("#modal1").modal("hide");
}
});
}
</script>
</div>