2

I want to go to the next step if the ajax call is successful, but i am not able to call the smart wizard methods inside the ajax call. My code is here.

var wizard = $("#listing_wizard").smartWizard({onLeaveStep:stepSubmit});

    //stepsubmit
    function stepSubmit(){
      var that = this;
      //that.goForward  ------- working here
      var step_no = this.curStepIdx+1;
      var form_data = $("#step_"+step_no+"_form").serialize();

      $.ajax({
        type:'post',
        url:"<?php echo URL_ADMIN ?>ajax.php",
        data:form_data,
        success:function(data){
          return that.goForward; //not working here
        }
      });
    }

I think the problem is here in these "this" so how can I call the smart wizard this.goForward after ajax call

Ravi
  • 163
  • 2
  • 11
  • Ummmm `that.goForward();` missing parentheses? – Ele Oct 25 '18 at 18:38
  • Tried that, but not working either, instead, that was causing unlimited ajax calls – Ravi Oct 25 '18 at 18:39
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Liam Aug 16 '19 at 07:35

1 Answers1

7

If you are using the latest Smart Wizard v4, here is the workaround.

$('#listing_wizard').smartWizard();

$("#listing_wizard").on("leaveStep", function(e, anchorObject, stepNumber, stepDirection) {

  var form_data = $("#step_"+ stepNumber +"_form").serialize();

  $.ajax({
    type:'post',
    url:"<?php echo URL_ADMIN ?>ajax.php",
    data:form_data,
    success:function(data){
       // indicate the ajax has been done, release the next step
       $("#listing_wizard").smartWizard("next");
    }
  });

  // Return false to cancel the `leaveStep` event 
  // and so the navigation to next step which is handled inside success callback.
  return false;

});

This is already addressed on How to wait ajax done to process next step?
Also refer the documentation jQuery Smart Wizard 4: Documentation

Dipu Raj
  • 1,784
  • 4
  • 29
  • 37