JohnOP Posted July 30, 2011 Share Posted July 30, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/243235-process-php-call-onclick/ Share on other sites More sharing options...
trq Posted July 30, 2011 Share Posted July 30, 2011 a link wont have a post or get value of course Links actually execute a HTTP GET request. Quote Link to comment https://forums.phpfreaks.com/topic/243235-process-php-call-onclick/#findComment-1249250 Share on other sites More sharing options...
JohnOP Posted July 30, 2011 Author Share Posted July 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243235-process-php-call-onclick/#findComment-1249255 Share on other sites More sharing options...
trq Posted July 30, 2011 Share Posted July 30, 2011 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') Quote Link to comment https://forums.phpfreaks.com/topic/243235-process-php-call-onclick/#findComment-1249257 Share on other sites More sharing options...
JohnOP Posted July 30, 2011 Author Share Posted July 30, 2011 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/243235-process-php-call-onclick/#findComment-1249261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.