Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have worked much in C# but bit new in ajax/webservice.

I know to call asmx webservice from script in sync/async manner using async attribute like...
eg.

JavaScript
$.ajax({ 
     type: "POST",
     url: "/Webservice/webservice1.asmx/SomeMethod",
     async: false,
     success: successMethod
});

but now I am calling the same using ajax script manager and from separate script file
eg.

JavaScript
function CallService(){
   var webServiceProxy = new testNamespace.Webservice.webservice1();
   //Code runs before calling webservice
   webServiceProxy.SomeMethod(successMethod);
   //codeLocation2
}

function successMethod(result) {
}

Now when I call the CallService Function the code @ codeLocation2 runs without waiting to the response from the webservice. So is that possible to wait for the result or successmethod execution before running codeLocation2 or need to write that into successMethod only.

In such case how to pass data from main function to success method.
Thanks in Advance.
Posted
Comments
Nathan Minier 14-Aug-14 11:47am    
Have you tried an assignment to trick the function into dummy synchronous operation?
var wait = webServiceProxy.SomeMethod(successMethod);
Nipesh Shah 15-Aug-14 4:19am    
I have tried after your comment, it is returning some object. but code2 and result occurs at a same time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900