Jump to content

Process Php Call OnClick


JohnOP

Recommended Posts

I have a add friend link and when clicked it will change the text to friend request sent without page refresh, what i want is to also call a php file and insert the request to the database so the person whom adding can get it, im not sure i can use the ajax function for this because it uses the type ='get' etc and a link wont have a post or get value of course.

 

<a id="addFriend" href="#">Add Friend</a><br />

<script type="text/javascript">
$(document).ready(function()
{

setInterval(function() {


}, 3000 ); // 3000 = 3 seconds

$("#addFriend").click(function (){

setInterval(function() {

$("#addFriend").html("<i>Friend Request Sent</i>");

}, 800);

});

});
</script>

Link to comment
https://forums.phpfreaks.com/topic/243235-process-php-call-onclick/
Share on other sites

I tried

 

<a id="addFriend" href="#" user="<?php echo $user; ?>">Add Friend</a><br />


$(document).ready(function()
{

setInterval(function() {


}, 3000 ); // 3000 = 3 seconds

$("#addFriend").click(function (){

setInterval(function() {

$.ajax({ 
$.get("addfriend.php", { 
user: $(this).attr('user') 
}), 
});
$("#addFriend").html("<i>Friend Request Sent</i>");

}, 800);

});

});
]

 

So should pass the user to addfriend.php so i can query the database on that value but nothing happends.

I think i got it with this

 

$(document).ready(function()
{

setInterval(function() {


}, 3000 ); // 3000 = 3 seconds

$("#addFriend").click(function (){

setInterval(function() {

$.ajax("addfriend.php", { 
user: $('#addFriend').attr('user') 
}), 
$("#addFriend").html("<i>Friend Request Sent</i>");

}, 800);

});

});


//addfriend.php
<?php

$user = $_GET['user'];
echo $user;

?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.