Reputation: 6829
I am trying to trigger action via ajax but it doesn't call from some reason. Is my js code fine?
@Html.ActionLink("LIKE", "LikeComment", "Comments", new { id = 1985 }, new{@class = "likeButton"})
$(document).ready(function () {
$(".likeButton").click(function () {
$.ajax({
url: $(this).data("action-url"),
cache: false,
success: function (html) {
alert('ss');
}
});
return false;
});
});
Upvotes: 0
Views: 133
Reputation: 1415
If your button code is LIKE then this part of ajax request is wrong:
This is wrong url: $(this).data("action-url"),
Do it like this url: $(this).attr("href"),
Upvotes: 1
Reputation: 887
try this
$(document).ready(function () {
$(".likeButton").click(function () {
$.ajax({
url: $(this).attr("href"),
cache: false,
success: function (html) {
alert('ss');
}
});
return false;
});
});
Upvotes: 1