Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to wait ajax done to process next step? #20

Closed
duongtdvn opened this issue Mar 15, 2017 · 2 comments
Closed

How to wait ajax done to process next step? #20

duongtdvn opened this issue Mar 15, 2017 · 2 comments

Comments

@duongtdvn
Copy link

Hi,

I have a wizard with 3 steps and in the step 2 I want to send an ajax request, how do i wait for the ajax call finish to show the step 3 which indicate the wizard has been finished?

My current code as bellow:

$wizard.on('leaveStep', function(e, anchorObject, stepNumber, stepDirection) {
  if (stepDirection === 'forward' && stepNumber === 2) {
    $.ajax({
      method: 'POST',
      url: url,
      data: data
    }).then(function (response) {
      // indicate the ajax has been done, release the next step
      return true;
    }, function (){
      // hang on this step if the error occur
      return false;
    });
  }
});
@techlab
Copy link
Owner

techlab commented Mar 15, 2017

Let's try this way, cancel the leaveStep event on step 2 and call next when the ajax is done. This may be endup in recursively calling leaveStep event for step 2, so we could use a flag(ajaxInvoke) to check if the ajax is already invoked. What you think?

var ajaxInvoke = false;
$wizard.on('leaveStep', function(e, anchorObject, stepNumber, stepDirection) {
  if (stepDirection === 'forward' && stepNumber === 2 && ajaxInvoke ==false) {
   ajaxInvoke = true;
    $.ajax({
      method: 'POST',
      url: url,
      data: data
    }).then(function (response) {
      // indicate the ajax has been done, release the next step
      $wizard.smartWizard("next");
    }, function (){
      // hang on this step if the error occur
    });
   return false;
  }
});

@techlab techlab closed this as completed Mar 17, 2017
@duongtdvn
Copy link
Author

Hi, im sorry for not response for that long. Your idea is perfectly fit what i want, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants