2010-08-29 102 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; 

,看看它是否工作。