Ajax成功后如何在智能向导中前进

时间:2018-10-25 18:35:42

标签: javascript jquery ajax smart-wizard

如果ajax调用成功,我想转到下一步,但是我无法在ajax调用内调用智能向导方法。我的代码在这里。

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

1 个答案:

答案 0 :(得分:1)

如果您使用的是最新的Smart Wizard v4,请使用以下解决方法。

$('#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;

});

此问题已在How to wait ajax done to process next step?上解决了
另请参阅文档jQuery Smart Wizard 4: Documentation