executing REST service from JS - how to synchronize
I need help, I am executing below service and I have a alert msg inside the success clause of execute service and then I have alert msg outside the execute service. Ideally it should execute the service first and then call the second alert but instead its calling second alert first.
How to synchronize execute and subsequent statements in JS? Please advise. I read various similar question on this topic but couldnt get it working. I tried using deffered object.
What I am trying to achieve is by calling service I am populating variable dynARef and then add this variable value to 'a' tag by using statement $(this).find("div").find("a").html(dynARef) but the value is blank as its executing $(this).find("div").find("a").html(dynARef) and executeservice asynch manner. Please advise?
$.when (myservicename.execute({})
.done(function() {
alert("Refresh Data1");
});
myservicename.execute({"data":
{ "where": whereclausevalue },
"success": function( data ){
alert("Inside the success method of execute service");
dynARef = data[0].value;
}});
//and then I have one more alert msg out side execute serivce
alert("After execute service......");
$(this).find("div").find("a").html(dynARef);
assign some the value