How to output result after ajax success

Am trying to display success message when the user follow and unfollow…with the code below nothing is display to tell the user that he/she have successfully follow/unfollow…any help and if I have to add new element with the html that display the follow/unfollow button…

$(function() {
$(".follow").click(function(){
var element = $(this);
var user_id = element.attr("id");
var info = 'id=' + user_id;

 $.ajax({
   type: "POST",
   url: "add_follow.php",
   data: info,
   success: function(){
        $('#remove'+I).fadeIn(200).show();
   }

 });

return false;

});

});


$(function() {
$(".remove").click(function(){
var element = $(this);
var user_id = element.attr("id");

var info = 'id=' + user_id;

 $.ajax({
   type: "POST",
   url: "remove.php",
   data: info,
   success: function(){

      $('#remove'+I).fadeOut(200).hide();

   }
 });
 
return false;

});

});







     {
        //this display unfollow button
        echo "<li id='remove$comID'><a href='#' class='remove' id='$comID' >Following</a></li>";
        }
        else {
        // this display follow button
        echo "<li id='follow$comID'><a href='' class='follow' id='$comID' >Follow company</a></li>";
    }

What is the I variable supposed to refer to?

@Paul_Wilkins the I is mistype, refer to nothing, just ignore it…

after

('#remove').fadeOut(200).show();

I want to display success message…any help?

reference the spot in the page where you want the message to appear and add the message into the page.

1 Like

@felgall thanks for your response…that what I want to do but dont know how I can reference the spot from the ajax…

am thinking of adding a div with id=“success” within the page and target it when the ajax is successful. how can I do that?

:smile::smile::smile:… I have been able to work it out…I can now display success message for each button.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.