2012-04-16 58 views
0

我試圖通過ajax觸發操作,但它不會因某種原因而調用。我的js代碼很好嗎?Ajax不會觸發服務器動作

@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; 
     }); 
    }); 
+1

.likeButton的元素是什麼樣的? – RubbleFord 2012-04-16 11:08:43

+0

1110 2012-04-16 11:13:32

回答

1

試試這個

$(document).ready(function() { 
     $(".likeButton").click(function() {    
      $.ajax({ 
       url: $(this).attr("href"), 
       cache: false, 
       success: function (html) { 
        alert('ss'); 
       } 
      }); 
      return false; 
     }); 
    }); 
+0

無法加載reource:HTTP://localhost/Project.GUI/Comments/LikeComment/1985 _ =,如果你只使用一個「」標籤如下1334575125907 – 1110 2012-04-16 11:20:51

+0

不會出現這種情況, Jayanga 2012-04-16 11:23:11

1

如果您的按鈕代碼是 LIKE 然後Ajax請求的這一部分是錯誤的:

這是錯誤 網址:$(本)。數據(「action-url」),

是否這樣做 url:$(this).attr(「href」),