Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 15, 2012 02:59 AM by BU XI - MSFT
0 Points
5 Posts
May 12, 2012 05:02 AM|LINK
Hi. Im wrote an AJAX code:
$.ajax({ type: "POST", url: "ShortList.aspx/SwapPlayers", data: JSON.stringify({ name1: name, name2: temp }), contentType: "application/json; charset=utf-8", dataType: "json", success: GetShortListPlayers() });
The problam is that the Success function (GetShortListPlayers) is called the WebMethod (SwapPlayers) called.
I need to call the Success function after the WebMethod is done for it will get the update details.
Any idea how i can do it?
Star
12363 Points
1860 Posts
May 12, 2012 05:06 AM|LINK
use async:false in ajax request.
$.ajax({ type: "POST", url: "ShortList.aspx/SwapPlayers", async: false, data: JSON.stringify({ name1: name, name2: temp }), contentType: "application/json; charset=utf-8", dataType: "json", success: GetShortListPlayers() });
May 12, 2012 05:07 AM|LINK
thank you vary much
May 12, 2012 05:26 AM|LINK
something realy wierd with this ajax. i did what you sayed, and the order was good for the 2 first calls.
but after that, it happend again. ive tryed to restart my project and again, the 3 first times was ok and then again.
you know about this problem?
.
All-Star
22367 Points
2704 Posts
Microsoft
May 15, 2012 02:59 AM|LINK
Hello
The AJAX way is asnychronous. So even though your code comes first, the response may not come back first. One option is to have a callback for the parameter and execute it after the other code has finished. For example,
function web_method ( success_fn ) {
// web_method logic
$.ajax({
....
success: success_fn
});
}
marco85
0 Points
5 Posts
Problem with the order of actions
May 12, 2012 05:02 AM|LINK
Hi. Im wrote an AJAX code:
$.ajax({
type: "POST",
url: "ShortList.aspx/SwapPlayers",
data: JSON.stringify({ name1: name, name2: temp }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: GetShortListPlayers()
});
The problam is that the Success function (GetShortListPlayers) is called the WebMethod (SwapPlayers) called.
I need to call the Success function after the WebMethod is done for it will get the update details.
Any idea how i can do it?
urenjoy
Star
12363 Points
1860 Posts
Re: Problem with the order of actions
May 12, 2012 05:06 AM|LINK
use async:false in ajax request.
$.ajax({ type: "POST", url: "ShortList.aspx/SwapPlayers", async: false, data: JSON.stringify({ name1: name, name2: temp }), contentType: "application/json; charset=utf-8", dataType: "json", success: GetShortListPlayers() });marco85
0 Points
5 Posts
Re: Problem with the order of actions
May 12, 2012 05:07 AM|LINK
thank you vary much
marco85
0 Points
5 Posts
Re: Problem with the order of actions
May 12, 2012 05:26 AM|LINK
something realy wierd with this ajax. i did what you sayed, and the order was good for the 2 first calls.
but after that, it happend again. ive tryed to restart my project and again, the 3 first times was ok and then again.
you know about this problem?
marco85
0 Points
5 Posts
Re: Problem with the order of actions
May 12, 2012 05:26 AM|LINK
.
marco85
0 Points
5 Posts
Re: Problem with the order of actions
May 12, 2012 05:26 AM|LINK
.
BU XI - MSFT
All-Star
22367 Points
2704 Posts
Microsoft
Re: Problem with the order of actions
May 15, 2012 02:59 AM|LINK
Hello
The AJAX way is asnychronous. So even though your code comes first, the response may not come back first. One option is to have a callback for the parameter and execute it after the other code has finished. For example,
function web_method ( success_fn ) {
// web_method logic
$.ajax({
....
success: success_fn
});
}
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework