I am using javascript remoting to get data from apex method.
My problem is javascript remoting is working Asynchronously.I want to work it as synchronously.
Please suggest me.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityBy definition, VF remoting (like AJAX) is asyncrhonous. As the official documentation states "The remote method call executes synchronously, but it doesn’t wait for the response to return. When the response returns, the callback function handles it asynchronously."
This link would help explain how to use the associated parameters when firing a remoting call -
Depending on what your exact use case is, you may want to handle the behavior appropriately in your callback function.
Use the below format
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.ControllerName.methodname}',
var1,var2,
function(result, event){
if (event.status) {
//all code after remote controller will be here
},
{escape: true}
);