3

最初のクリックでのみ ajax を呼び出して、データが膨大な帯域幅を節約したいと考えています。以下は私のコードです

$('.id-list').click(function() {
$.ajax({
    type: "POST",
    url: "timesheet.php?action=idlist",
    async: false,
    success: function(rdata) {
             $('.id-list').removeClass('id-list') //remove the class
    }
})      
})

要素の検査class="id-list"は削除されましたが、もう一度クリックすると、発生したくない ajax 呼び出しが再びトリガーされます。

これを実装する方法はありますか?ありがとう。

4

3 に答える 3

3

また

API .one: http://api.jquery.com/one/

要素のイベントにハンドラーをアタッチします。ハンドラは要素ごとに最大 1 回実行されます。

   $('.id-list').one('click', function() {
    $.ajax({
    type: "POST",
    url: "timesheet.php?action=idlist",
    async: false,
    success: function(rdata) {
             $('.id-list').removeClass('id-list') //remove the class
    }
})      
})
于 2012-07-15T06:32:34.957 に答える
2

http://api.jquery.com/one/

説明:要素のイベントにハンドラーをアタッチします。ハンドラは要素ごとに最大 1 回実行されます。

$('.id-list').one("click",function() {
  $.ajax({
    type: "POST",
    url: "timesheet.php?action=idlist",
    async: false,
    success: function(rdata) {
             $('.id-list').removeClass('id-list') //remove the class
    }
  })      
})
于 2012-07-15T06:33:59.090 に答える
0

http://api.jquery.com/live/

$('.id-list').live("click", function(){
$.ajax({
    type: "POST",
    url: "timesheet.php?action=idlist",
    async: false,
    success: function(rdata) {
         $('.id-list').removeClass('id-list') //remove the class
    }
})
});
于 2012-07-15T06:33:01.327 に答える