2010-08-29 89 views
1

我有一個調用.asmx web服務的jQuery方法。 jQuery方法只執行一次,但Web服務執行多次。jQuery多次調用asmx web方法

這是調用Web服務

// Expand copy to group modal groups 
     $(".groupZones .expand").live('click', function() { 
      $(this).siblings('.contract').show(); 
      $(this).css('display', 'none'); 
      $(this).parent().parent().siblings('.groupDetails').css('display', 'block'); 
      $(this).parent().parent().siblings('.groupDetails').find('ul.device').find('ul .list').after(''); 
      var cwpUserId = $('#ctl00_cphBody_hfCwpId').val(); 
      var groupId = $(this).parent().siblings('.add').find('input').val(); 
      sortOn = "Location"; 
      var mode = "dayparts"; 
      var groupUl = $(this).parent().parent().siblings('.groupDetails').find('ul').find('ul li.head'); 
      var groupDetails = $(this).parent().parent().siblings('.groupDetails'); 
      //Get the zone details.. 
      // Load. 

      $.ajax({ 
       type: "POST", 
       url: "ajax/DaypartMessagingGroups.asmx/GetDetailsForCopyToGroup", 
       data: "{'groupId':" + groupId + ",'cwpUserId':" + cwpUserId + ",'pageNum':0,'pageSize':5, 'sortOn':'" + sortOn + "','sortDirection':'" + sortDirection + "','mode':'" + mode + "'}", 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: function(msg) { 
        //$(btn).parents("ul.list-group-zones").children("li:.head").after(msg.d); 
        $(groupUl).after(msg.d); 
        $('.location').find('.contract').hide(); 

        var copyZonePerPage = 5; 
        //var copyZoneItemsCount = $(groupUl).siblings('#hfAllGroupZones').val(); 
        var copyZoneItemsCount = $('#hfAllGroupZones').val(); 
        var copyZonePages = Math.ceil(copyZoneItemsCount/copyZonePerPage); 
        var copyZoneHtml = ''; 
        var copyZoneCurLink = 0; 
        var current_copyzone_pagination_set = 1; 
        var num_of_pagination_shown = 0; 
        alert('Line 2113 CBG'); 

        if (copyZonePages > 20) { 
         //var pagesAdded = (parseInt(current_copyzone_pagination_set) - 1) * 10; 

         while (num_of_pagination_shown < 20) { 
          copyZoneHtml += '<a class="page_link_clicked" longdesc="' + copyZoneCurLink + '">' + (copyZoneCurLink + 1) + '</a>'; 
          copyZoneCurLink++; 
          num_of_pagination_shown++; 
         } 

         copyZoneHtml += '<a class="page_link" id="btnNextZoneSet" longdesc="' + copyZoneCurLink + '">...</a>'; 

        } 
        else { 
         while (copyZonePages > copyZoneCurLink) { 
          copyZoneHtml += '<a class="page_link_clicked" longdesc="' + copyZoneCurLink + '">' + (copyZoneCurLink + 1) + '</a>'; 
          copyZoneCurLink++; 
         } 
        } 

        $(groupUl).parent().parent().find('ul li.footer').html(copyZoneHtml); 
        $('.page_link_clicked[longdesc=0]').addClass('current'); 

       }, 
       error: function(err) { 
        var err = eval("(" + err.responseText + ")"); 
        if (ShowModalLogin(err.ExceptionType)) { 
         alert("An error occurred."); 
        } 
       } 
      }); 

     }); 

做更多的測試,我看到後實際上是被反覆numberous次後jQuery代碼。

+3

如何發佈您的JS代碼 – 2010-08-29 20:04:46

+0

你打電話給asmx web服務?如果你發佈一些代碼,它會有很大的幫助。 – OneDeveloper 2010-08-30 08:51:35

回答

0

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

要使用.live()一個約束後停止執行進一步的處理程序,處理程序必須返回false。調用.stopPropagation()將無法完成此操作。

我不知道如果在這裏適用,但你可以在你的點擊處理程序的末尾添加

return false; 

,看看它是否工作。