请问Ajax如何获取回调函数的返回值?
C#code[WebMethod]publicstaticstringGetPassword(){stringpassword=CommonFunctions.GetMi...
C# code
[WebMethod]
public static string GetPassword()
{
string password = CommonFunctions.GetMixPwd(6);
return password;
}
#endregion
javascript代码
function ResetPassword() {
return PageMethods.GetPassword(Password_CallBack);
}
function Password_CallBack(response) {
document.getElementById('hiddenPassword').value = response;
return confirm('The password has been reset to ' + response + ' , do you want to send email?');
}
HTML code
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<prog:Button ID="btnResetPwd" runat="server" Text="Reset Pwd" CssClass="ButtonUnfixed" ValidationGroup="2" OnClientClick="return ResetPassword();" onclick="btnResetPwd_Click"/>
大侠帮帮忙了!或者指点一个替代的方法。谢谢! 展开
[WebMethod]
public static string GetPassword()
{
string password = CommonFunctions.GetMixPwd(6);
return password;
}
#endregion
javascript代码
function ResetPassword() {
return PageMethods.GetPassword(Password_CallBack);
}
function Password_CallBack(response) {
document.getElementById('hiddenPassword').value = response;
return confirm('The password has been reset to ' + response + ' , do you want to send email?');
}
HTML code
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<prog:Button ID="btnResetPwd" runat="server" Text="Reset Pwd" CssClass="ButtonUnfixed" ValidationGroup="2" OnClientClick="return ResetPassword();" onclick="btnResetPwd_Click"/>
大侠帮帮忙了!或者指点一个替代的方法。谢谢! 展开
2个回答
展开全部
function Password_CallBack(response) {
document.getElementById('hiddenPassword').value = response;
//这里取消 return confirm('The password has been reset to ' + response + ' , do you want to send email?');
//改为:
if(confirm('The password has been reset to ' + response + ' , do you want to send email?'))
{
//在这里再发起一次ajax请求,在server端实现发送email重置密码的通知.
//response就是你的hiddenPassword
//说实话,是不需要使用hiddenPassword这个控件的...response就已经是重置过的密码了.
}
}
document.getElementById('hiddenPassword').value = response;
//这里取消 return confirm('The password has been reset to ' + response + ' , do you want to send email?');
//改为:
if(confirm('The password has been reset to ' + response + ' , do you want to send email?'))
{
//在这里再发起一次ajax请求,在server端实现发送email重置密码的通知.
//response就是你的hiddenPassword
//说实话,是不需要使用hiddenPassword这个控件的...response就已经是重置过的密码了.
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询