2010-08-29 2 views
1

J'ai une méthode jQuery qui appelle un service Web .asmx. La méthode jQuery s'exécute uniquement une fois mais le service Web s'exécute plusieurs fois.jQuery appelle plusieurs fois la méthode Web asmx

c'est le code jQuery qui appellent le service 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."); 
        } 
       } 
      }); 

     }); 

après avoir fait plus d'essais que je vois ce poste est effectivement répété fois numberous.

+3

Comment postuler votre code JS –

+0

comment appelez-vous le webservice asmx? cela aiderait beaucoup si vous postez du code. – OneDeveloper

Répondre

0

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

pour arrêter la manipulateurs d'exécuter après un bond en utilisant .live(), le gestionnaire doit retourner false. Appeler .stopPropagation() n'effectuera pas cela.

Je ne sais pas si cela va, mais vous pouvez ajouter un

return false; 

à la fin de votre gestionnaire de clic et voir si cela fonctionne.

Questions connexes