开发者

Weird Asynchronous Javascript & WebMethod Behavior

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


Instead of passing the return value of your handler functions, ie onSuccess() and onError1(), pass the functions themselves, ie onSuccess and onError1.


Should be:

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


There's a stateNetworkTimeout tag involved with the sessionState. Like this:

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

I didn't have a stateNetworkTimeout, sure enough it bombed every time.

Thanks Mrchief!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜