Uncertain about the issue you're facing, but here's my approach to handling it. This method circumvents problems when dealing with alphanumeric post IDs by appending them to the href and extracting them from there. The content remains hidden initially and is only revealed if JavaScript is enabled, a necessary requirement for functionality.
To diagnose your problem, consider incorporating an error handler and utilizing Firefox/Firebug to monitor the requests (and responses) being made.
<a class="like" href="#<?php echo $post_id; ?>");" style="display: none'">Like Post</a>
<script type="text/javascript">
$(function() {
$('.like').show().click( function() {
var post_id = $(this).attr('href').replace(/^#/,'');
$.ajax({
async:true,
dataType:"html",
success:function (data, textStatus) {
$("#post-"+post_id+"-like").html(data);
},
url: "domain/likes/like/"+post_id
});
return false;
}
</script>
A different method to cater to both JavaScript-enabled and non-JavaScript browsers
Note: Your backend code must differentiate between AJAX and non-AJAX requests. This can be accomplished using the X_REQUESTED_WITH header (HTTP_X_REQUESTED_WITH) injected by jQuery during AJAX calls. Exercise caution while relying on this check, avoiding authentication or authorization decisions based solely on it. For AJAX requests, simply return the HTML snippet. Non-AJAX requests will necessitate rendering the entire page again.
<a class="like" href="/domain/likes/like/<?php echo $post_id; ?>");">Like Post</a>
<script type="text/javascript">
$(function() {
$('.like').show().click( function() {
var url = $(this).attr('href');
$.ajax({
async:true,
type: 'post', // technically it changes data so post is RESTful
dataType:"html",
success:function (data, textStatus) {
$("#post-"+post_id+"-like").html(data);
},
url: url
});
// cancel the default link action so we don't get two like's
return false;
}
</script>