【问题标题】:Weird Asynchronous Javascript & WebMethod Behavior奇怪的异步 Javascript 和 Web 方法行为
【发布时间】:2011-07-13 16:50:37
【问题描述】:

我在 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 行代码),在我可以进入我的代码之前,我会收到两个警报框。两个警报,然后我的代码中断了。

这对我来说毫无意义。我错过了什么吗?

谢谢,

杰森。

附: -- 这里是 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

【问题讨论】:

    标签: javascript asp.net asynchronous webmethod pagemethods


    【解决方案1】:

    不要传递处理函数的返回值,即 onSuccess() 和 onError1(),而是传递函数本身,即 onSuccess 和 onError1。

    【讨论】:

    • 之前尝试过,结果相同
    • 我严重怀疑。如果没有这种变化,它就不可能工作。
    【解决方案2】:

    应该是:

    PageMethods.AuthenticateAndDelete(
            userInfo,
            pswd,
            onSuccess,
            onError1);    
      }    
    

    【讨论】:

    • 我删除了括号,现在我没有收到任何消息框。
    • 果然是。将发布答案以便将其编入索引,但会将您的答案标记为答案并投票。谢谢!!!
    【解决方案3】:

    sessionState 涉及一个 stateNetworkTimeout 标签。像这样:

    <sessionState timeout="540" stateNetworkTimeout="5"></sessionState>
    

    我没有stateNetworkTimeout,果然每次都被炸了。

    谢谢大夫!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 2015-12-29
      相关资源
      最近更新 更多