通过JQuery.Ajax发布和更改HTML传递PHP

I'm trying to create a facebook style like/unlike link and I need to pass some php variables through the JQuery. At the moment I'm passing:

<a class="likelink" href="like.php?id=****&username=****&type=****">Like</a>

But although this works it is refreshing the page and I want it to do it fluently like twitter or facebook, so I need to pass the id, username, etc through JQuery.Ajax post. Can anyone tell me how this would be possible? Also then I want the .likelink to change to Unlike.

Thanks

You could do something along the lines of:

$('.likelink').on('click', function(e){
  var $this = $(this);
  $.get($this.attr('href'), function(){
    $this.addClass('liked').attr('href', unlikeLink).text('Unlike');
  });
  e.preventDefault();
});

Use an ajax request for the 'like' action and then change the class in the success callback function:

$('.likelink').on('click', function(e){
  e.preventDefault();
  $.ajax({
    url: 'like.php',
    data: {
      id: ***,
      username: ****,
      type: ****
    },
    success: function() {
      $('.likelink').removeClass('likelink').addClass('unlikelink');
    }
  });
});