我第一次使用AJAX,我不确定是否有正确的语法。基本上我在后面的代码中有一个方法,它接受2个字符串参数并执行更新用户密码。但它一直失败。JQuery AJAX请求无法正常工作。
这是我目前的ASP按钮:
<td><asp:Button ID="Button1" runat="server" Text="Add Password" alt="Add Password" /></td>
这是执行,一旦用户点击窗体上添加密码按钮的代码:
$("#edit_password_form").submit(function (e) {
e.preventDefault();
var finalValue = value2.value;
<%string inputCust = Session[SessionKey.CUSTOMER_ID].ToString();%>
var custNoString = <%=inputCust%>
$.ajax({
url: 'reciept.aspx/Button1_Click',
method: 'post',
contentType: 'application/json',
data: '{custID:' + custNoString + 'tempPass2:' + finalValue + '}',
success: function(){
alert("The function worked correctly");
},
error:function(){ alert("the function did not succeed");}
});
});;
为什么它可能是任何想法失败? Mayb我缺少一个ajax键或者我的语法可能关闭。
让我知道!谢谢。
请不要将您的数据作为字符串传递,而应将其作为对象传递。 '数据:{custID:custNoString,tempPass2:finalValue}'。 –
备注:考虑使用常规按钮而不是提交按钮。在按钮点击事件中调用你的函数。这将允许你摆脱'e.preventDefault()'。 –