【问题标题】:jquery Ajax call only firing oncejquery Ajax 调用只触发一次
【发布时间】:2012-11-14 23:12:35
【问题描述】:

Jquery Ajax 调用仅在之后触发一次,如果我单击按钮,它会返回最后返回的响应,但不会执行 c# 中的 ajax 函数 这是我的aspx代码

 <asp:ImageButton ID="iBtnSaveUser" runat="server" OnClientClick="return ValidateForm();" />

这是我的 jquery Ajax 函数

    function ValidateForm() {
    if ($(txtName).val() == "") {
        alert('Name Required');
        return false;
    }
    else if ($(txtUserName).val() == "") {
        alert('UserName Required');
        return false;
    }
    else if ($(txtPassword).val() == "") {
        alert('Password Required');
        return false;
    }
    else if ($(txtEmail).val() == "") {
        alert('Email Required');
        return false;
    }
    else if ($(txtPhone).val() == "") {
        alert('Phone Number Required');
        return false;
    }
    else if ($(ddlProfile).val() == "") {
        alert('Profile Required');
        return false;
    }
    AddUser();
    return false;
}

    function AddUser() {
        var name = $(txtName).val();
        var userName = $(txtUserName).val();
        var password = $(txtPassword).val();
        var email = $(txtEmail).val();
        var phone = $(txtPhone).val();
        var profile = $(ddlProfile).val();
        $.ajax({
            type: "GET",
            url: ajaxCallHandlerUrl,
            data: { OpCode: "AddUser", Params: "Name^" + name + "~UserName^" + userName + "~Email^" + email + "~Phone^" + phone + "~Profile^" + profile +"~Password^"+password },
            dataType: "",
            success: function (responseString) {
                alert(responseString);
            }
        });
    }

【问题讨论】:

    标签: c# javascript jquery asp.net ajax


    【解决方案1】:

    尝试关闭缓存:

    $.ajax({
        cache: false,
        type: "GET",
        /* other params... */
    });
    

    【讨论】:

      【解决方案2】:

      试试下面的代码:

      @Rory McCrossan 输入的代码不起作用。

      $(document).ready(function() {
        $.ajaxSetup({ cache: false });
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多