I have a button that sends the data to the database with Ajax. But How would I make this button change to friend requested automatically once this data is sent through?
Would I put my friend requested/revoke button in the success to replace it?
Add friend button
<button cursor='pointer' onClick=\"addfriend(".$user2_id.");\">Add Friend</button>
AJAX
function addfriend(user2_id){
$.ajax({
type: "POST",
url: "../add_friend.php",
data: "user2_id="+user2_id,
success: function(){
}
});
}
You may do this with the help of a database. The target user id may be attached to this user database or table. A class echo may be made using php if matching user id is found. The button may be given a specific class using
php echoand the button may be styled differently usingCSS. Also you may disable AJAX request for that button (by specifying AJAX function for some active class button only).Try this;
In your php;
and in your button part;
Finally your CSS