2012-11-27 124 views
2

jQuery的Ajax調用,如果我點擊按鈕後,僅觸發一次它返回最後返回效應初探,但不走C#中的AJAX功能 這裏是我的aspx代碼jQuery的Ajax調用只發射一次

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

回答

5

嘗試關閉緩存:

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

請嘗試以下代碼:

對於@Rory McCrossan輸入的代碼無效。

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