2

如果 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
        }
      });
    }

我认为问题出在这些“this”中,所以在 ajax 调用之后如何调用智能向导 this.goForward

4

1 回答 1

7

如果您使用的是最新的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;

});

这已经在如何等待 ajax 完成以处理下一步?
另请参阅文档jQuery Smart Wizard 4:文档

于 2018-10-26T04:35:10.540 回答