Demon Demon - 3 months ago 5x
PHP Question

Ajax add record with session id and user id issue

I have an add friend system and i want to make an ajax call but it is not working, i want ajax to insert in the table the session id (me) and friend id,but i have no luck, i am a begginer.


var u = "<?php echo $_SESSION["user"];?>";
var f = "<?php echo $_GET["u"];?>";
type: "POST",

url: "?u="+u+"&add="+f,
success: function(){

<a id='add' class='btn btn-success' href=\"#\">Add as friend</a>

Any help apreciated! Thanks.


since you are sending a "post" request this will be never handled you had to send it with a "GET" method see this it may help

   var u = `"<?php echo $u->id?>"` <--- this is friend id
 var id = "<?php echo  $_SESSION['user']";?> <---- this is my id

          type: "GET",
          url : "?u="+u+"&add="+id,
          success: function(data){//here the function should have a parameter which is the response of your request
             alert(data);//try to debug it and see what is the response or alert("success")

in you php file you can get those parameters simply by using $_GET["u"] and $_GET["add"] to use them in your request for inserting