奇怪的异步 Javascript 和Web方法行为
我正在 JavaScript 中调用 PageMethod。像这样:
function DeleteBatchJS2()
{$find('mdlPassword').hide();
var pswd = $('#txtPassword').val();
var userInfo = get_cookie("UserInfo");
PageMethods.AuthenticateAndDelete(
userInfo,
pswd,
onSuccess(),
onError1());
}
function onSuccess(result)
{alert(result);}
function onError1(result)
{alert(result);}
现在有一个奇怪的部分:人们会认为调用 PageMethods 会在运行时发出一 (1) 个警报。 onSuccess 函数或 onError1 函数。但是 - 我收到两个警报,都显示“未定义”。
事实上,当我在 VB 代码隐藏中放置断点(例如函数中的第 3 行或第 4 行代码)时,我会在进入代码隐藏之前收到两个警报框。两个警报,然后我的代码就崩溃了。
这对我来说毫无意义。我错过了什么吗?
谢谢,
杰森。
PS——这是 WebMethod 函数的源代码。另请注意,它确实会进行 WCF 调用。
<WebMethod()> _
Public Shared Function AuthenticateAndDelete(ByVal UserInfo As String, ByVal Password As String) As Boolean
Dim Client As New LetterWriterClient
Dim bo As New BatchOperations
Dim UserNumber As String
Dim UserName As String
'Extract the user name and number from the user info cookie string
UserName = GetValueFromVBCookie("UserName", UserInfo)
UserNumber = GetValueFromVBCookie("UserNumber", UserInfo)
'Now validate the user
If bo.ValidateActiveDirectoryLogin("Backoffice", UserName, Password) Then
AuthenticateAndDelete = Client.Delete_dat_BatchSQL(UserNumber)
Client.Close()
Else
AuthenticateAndDelete = False
End If
End Function
I'm calling a PageMethod in javascript. Like this:
function DeleteBatchJS2()
{$find('mdlPassword').hide();
var pswd = $('#txtPassword').val();
var userInfo = get_cookie("UserInfo");
PageMethods.AuthenticateAndDelete(
userInfo,
pswd,
onSuccess(),
onError1());
}
function onSuccess(result)
{alert(result);}
function onError1(result)
{alert(result);}
Now here's the strange part: One would think that calling PageMethods would give one (1) alert when running. Either the onSuccess function or the onError1 function. BUT -- I get two alerts, both saying "Undefined".
As a matter of fact, when I put a breakpoint in the VB code-behind (like the 3rd or 4th line of code in the function), I get BOTH alert boxes before I can step into my code behind. Two alerts, and THEN my code breaks.
This makes no sense to me. Am I missing anything?
Thanks,
Jason.
P.S. -- Here's the source for the WebMethod function. Please also note it does make a WCF call.
<WebMethod()> _
Public Shared Function AuthenticateAndDelete(ByVal UserInfo As String, ByVal Password As String) As Boolean
Dim Client As New LetterWriterClient
Dim bo As New BatchOperations
Dim UserNumber As String
Dim UserName As String
'Extract the user name and number from the user info cookie string
UserName = GetValueFromVBCookie("UserName", UserInfo)
UserNumber = GetValueFromVBCookie("UserNumber", UserInfo)
'Now validate the user
If bo.ValidateActiveDirectoryLogin("Backoffice", UserName, Password) Then
AuthenticateAndDelete = Client.Delete_dat_BatchSQL(UserNumber)
Client.Close()
Else
AuthenticateAndDelete = False
End If
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要传递处理函数的返回值,即 onSuccess() 和 onError1(),而是传递函数本身,即 onSuccess 和 onError1。
Instead of passing the return value of your handler functions, ie onSuccess() and onError1(), pass the functions themselves, ie onSuccess and onError1.
应该是:
Should be:
sessionState 涉及到一个 stateNetworkTimeout 标签。像这样:
我没有stateNetworkTimeout,果然每次都会爆炸。
谢谢酋长!
There's a stateNetworkTimeout tag involved with the sessionState. Like this:
I didn't have a stateNetworkTimeout, sure enough it bombed every time.
Thanks Mrchief!