0
By clicking on the positive board (indicated in the figure by an arrow), the user accepts the friendship invitation.
I need to pass the user id (value 15) to the update-friends.php page. The event is held by the invitations.js page :
$(document).ready(function(){
$("#aceitar").click(function(){
var id = ????????? ;
$.post('atualizar-amigos.php', {amigo:id}, function(){
$(".item").remove();
});
});
});
The user id is stored in the PHP variable $user_id. I tried:
var id = <?= $user_id?>;
var id = <?php echo $user_id; ?>;
var id = "<?php echo $user_id; ?>";
In the first 2 options, it gives error. In the third, the value passed is
"<?php echo $user_id;?>"
(and not the 15)
I also created JSON $frind (printed on image) and tried:
var id = frind['id'];
But tbm didn’t work. How I access the id value (in JSON) OR PHP variable ($user_id) in the Ajax post function?
has already answered the question itself..
var id = "<?php echo $user_id; ?>";
– Daniel Omine
Did you run these tests directly in the PHP file that contains HTML or in a JS file? Because it seems that PHP was not interpreted in the file, which indicates that the code is not in a PHP file.
– Woss