Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
奇怪的异步Javascript&;WebMethod行为_Javascript_Asp.net_Asynchronous_Webmethod_Pagemethods - Fatal编程技术网

奇怪的异步Javascript&;WebMethod行为

奇怪的异步Javascript&;WebMethod行为,javascript,asp.net,asynchronous,webmethod,pagemethods,Javascript,Asp.net,Asynchronous,Webmethod,Pagemethods,我正在用javascript调用PageMethod。像这样: function DeleteBatchJS2() {$find('mdlPassword').hide(); var pswd = $('#txtPassword').val(); var userInfo = get_cookie("UserInfo"); PageMethods.AuthenticateAndDelete( userInfo, pswd,

我正在用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);}
<sessionState timeout="540" stateNetworkTimeout="5"></sessionState>
现在有一个奇怪的部分:人们会认为调用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
_
公共共享函数AuthenticateAndDelete(ByVal UserInfo作为字符串,ByVal Password作为字符串)作为布尔值
Dim客户端作为新的LetterWriterClient
Dim bo作为新的批处理操作
Dim UserNumber作为字符串
将用户名设置为字符串
'从用户信息cookie字符串中提取用户名和号码
用户名=GetValueFromVBCookie(“用户名”,UserInfo)
UserNumber=GetValueFromVBCookie(“UserNumber”,UserInfo)
'现在验证用户
如果bo.ValidateActiveDirectoryLogin(“Backoffice”、用户名、密码),则
AuthenticateAndDelete=Client.Delete\u dat\u BatchSQL(UserNumber)
Client.Close()
其他的
AuthenticateAndDelete=False
如果结束
端函数

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

应该是:

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

sessionState包含一个stateNetworkTimeout标记。像这样:

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);}
<sessionState timeout="540" stateNetworkTimeout="5"></sessionState>

我没有stateNetworkTimeout,可以肯定的是,它每次都会爆炸


谢谢长官

我去掉了括号,现在两个messagebox都没有了。将发布答案以便索引,但会将您的答案标记为答案并进行投票。谢谢我早就试过了,结果也一样。我对此表示严重怀疑。没有这种改变,它是不可能工作的。