1110
1110

Reputation: 6829

Ajax doesn't trigger server action

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

Answers (2)

Vasily Komarov
Vasily Komarov

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

Jayanga
Jayanga

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

Related Questions