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
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.

Link to comment
Share on other sites

Firstly, either use $.get or $.ajax, but not $.get within $.ajax that makes no sense.

 

Also, within the $.get object $(this) refers to the $.get object itself. This line....

 

user: $(this).attr('user') 

 

would need to be....

 

user: $('#addFriend').attr('user') 

Link to comment
Share on other sites

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;

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.