2009-02-20 13 views
1

Je ne sais pas exactement pourquoi cela se produit, mais au clic d'un bouton j'appelle un contrôle JQuery Ajax, après que je ne veux pas continuer à soumettre le formulaire, mais avant que la page est encore soumise.JQuery Ajax formulaire de soumission

<asp:ImageButton id="btnContinue" OnClick="btnContinue_Click" runat="server" OnClientClick="return false;" /> 

et jQuery:

  $("#<%=btnContinue.ClientID%>").click(function() { 
      var currentpickupLocation = document.getElementById("<%=ddlPickupLocation.ClientID %>").value; 
      var currentpickupDate = document.getElementById("<%=txtPickupDate.ClientID %>").value; 
      var currentCulture = "<%= GetCulture() %>"; 
      var params = $.toJSON({pickupLocation: currentpickupLocation, pickupDate: currentpickupDate}); 
      $.ajax({ 
       type: "POST", 
       url: "LocationService.asmx/GetBlackoutDates", 
       data: params, 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: function(locations) { 
        return false; 
       } 
      }); 
     }); 

Répondre

2

Vous devez avoir une fausse déclaration dans la zone de clic comme ceci:

$("#<%=btnContinue.ClientID%>").click(function() { 
    var currentpickupLocation = document.getElementById("<%=ddlPickupLocation.ClientID %>").value; 
    var currentpickupDate = document.getElementById("<%=txtPickupDate.ClientID %>").value; 
    var currentCulture = "<%= GetCulture() %>"; 
    var params = $.toJSON({ 
     pickupLocation: currentpickupLocation, 
     pickupDate : currentpickupDate 
    }); 
    $.ajax({ 
     type: "POST", 
     url: "LocationService.asmx/GetBlackoutDates", 
     data: params, 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function(locations) { 
      return false; 
     } 
    }); 
    return false; //this tells the browser not to submit 
}); 
+0

Travaillé comme un charme, merci pour votre aide! – BoredOfBinary

+0

Pas de soucis, a couru dans ce comme il ya un an, heureux d'avoir pu aider. –

Questions connexes