且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JQuery的Ajax表单提交

更新时间:2022-12-11 14:41:48

您需要有一个回虚假的点击区域,像这样:

  $(#<%= btnContinue.ClientID%>中)。点击(函数(){
    VAR currentpickupLocation =的document.getElementById(<%= ddlPickupLocation.ClientID%>中)值。
    VAR currentpickupDate =的document.getElementById(<%= txtPickupDate.ClientID%>中)。值;
    变种的CurrentCulture =&其中;%= GetCulture()%>中;
    VAR PARAMS = $ .toJSON({
        pickupLocation:currentpickupLocation,
        pickupDate:currentpickupDate
    });
    $阿贾克斯({
        键入:POST,
        网址:LocationService.asmx / GetBlackoutDates
        数据:参数,可以
        的contentType:应用/ JSON的;字符集= UTF-8,
        数据类型:JSON,
        成功:函数(位置){
            返回false;
        }
    });
    返回false; //这告诉浏览器不提交
});
 

Not exactly sure why this is happening, but upon click of a button I call a JQuery Ajax control, after that I do not want to continue submitting the form, but before the page gets still submitted.

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

and the 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;
                }
            });
        });

You need to have a return false in the click area like so:

$("#<%=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
});