最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to go forward in smart wizard after ajax success - Stack Overflow

programmeradmin7浏览0评论

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

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

Share Improve this question asked Oct 25, 2018 at 18:35 RaviRavi 1733 silver badges11 bronze badges 3
  • Ummmm that.goForward(); missing parentheses? – Ele Commented Oct 25, 2018 at 18:38
  • Tried that, but not working either, instead, that was causing unlimited ajax calls – Ravi Commented Oct 25, 2018 at 18:39
  • Possible duplicate of How do I return the response from an asynchronous call? – Liam Commented Aug 16, 2019 at 7:35
Add a ment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论