2012-04-16 5 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

+0

1110

答えて

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

+0

次のようにあなただけの "" タグを使用している場合、これは 、起こらないのだろうか? – Jayanga

1

を試行し、AJAX要求のこの部分は間違っている:$(この):

は、これは間違った URLです。データ(「action-url」)、

このようにする url:$(this).attr( "href")、

関連する問題