Here's a something based on links class name, the php code is in your
hand ;)

[HTML PAGE]
[JQUERY CODE]

//add an action to each A with class="friends",
//the action is based on the id of each A and passed as variable (see
DATA: )
$("a.friends").each (
  function () {
        $( this ).bind (
          "click",
          function(){
                $.ajax({
                        type: "POST",
                        url: "test-ajax-simple.php",
                        data: "action="+$(this).attr("id")+"&friend="+$
("#friend").val(),
                        success: function(reponse){
                                                alert(reponse);
                                          },//function success
                        error: function (){ alert('something wrong with ajax!') 
}
                });//$.ajax
          }//function
        );//bind
  }//function
);//each


[ADD THIS BETWEEN <BODY></BODY> OF THE HTML PAGE]
<p>
  <a href="#add" class="friends" id="add_friend">Add friend</a> -
  <a href="#del" class="friends" id="delete_friend">Del friend</a>
</p>

Reply via email to