dany651
asked on
Ajax, how wait for the response of the PageMethods call result ?
Hi, make a call to a function in my code behind (C#) from javascript with Ajax
My function 'Test' call my Function 'Toto' and then after i have no control, my 'Test' function continue running, so my var MyResult is always null in my 'Test' method.
I would like to wait for the result of OnSucceedd to continue running my 'Test' function, so after the call to 'Toto' i have my var 'MyResult' set by the result of my OnSucceedd.
Here is my code :
var MyResult = null;
function Test()
{
Toto();
if(MyResult == true)
blablabla...
}
Toto()
{
PageMethods.FindRequesterN ameMatch(1 , 2, onSucceeded, onFailed);
}
function onSucceeded(result, userContext, methodName)
{
MatchExist = result;
}
function onFailed(error, userContext, methodName)
{
MatchExist = false;
}
My function 'Test' call my Function 'Toto' and then after i have no control, my 'Test' function continue running, so my var MyResult is always null in my 'Test' method.
I would like to wait for the result of OnSucceedd to continue running my 'Test' function, so after the call to 'Toto' i have my var 'MyResult' set by the result of my OnSucceedd.
Here is my code :
var MyResult = null;
function Test()
{
Toto();
if(MyResult == true)
blablabla...
}
Toto()
{
PageMethods.FindRequesterN
}
function onSucceeded(result, userContext, methodName)
{
MatchExist = result;
}
function onFailed(error, userContext, methodName)
{
MatchExist = false;
}
ASKER
I know but my Test function are called by a button ( OnClick="return Test();" ) so i want to verify the result before continue.....
TEST ==
result = called my webMethod via Ajax....
IF MyResult == true
return true to button and execute ButtonClick() server side code
ELSE
return false to button and stop process
TEST ==
result = called my webMethod via Ajax....
IF MyResult == true
return true to button and execute ButtonClick() server side code
ELSE
return false to button and stop process
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Correct, but once Toto has completed, it should call onSucceeded. So the if should really be in onSucceeded (although it's not clear where you are setting the value of MyResult):
Open in new window