简体   繁体   English

Ajax jQuery多步骤表单而不是重新加载div,只需添加新内容

[英]Ajax jQuery Multiple Step Form instead of reloading div, just append new content

I wonder if it's possible to do this multistep form on one single page, so not reloading the div with the content received from the php file but append it right below.. 我想知道是否有可能在一个页面上执行此多步骤表单,因此不要用从php文件接收到的内容重新加载div,而是将其附加在下面。

This is what I've got so far: 到目前为止,这是我得到的:

$(document).on('submit', '#reg-form', function(){
var ln = $('#submit').val();
var id = $('#id').val();

var data = 'submit='+ln;
  $.ajax({

  type: 'GET',
  url  : 'step.php',
  dataType : 'html',
  data : data,
  success :  function(data)
       {
      $('#reg-form').fadeOut(500).hide(function()
      {
       $('.result').fadeIn(500).show(function()
       {
        $('.result'+id).append(data);
       });
      });

       }

  });
       return false;

});

Also I tried to use different divs, with incremental id's to put every content in it's own div. 我也尝试使用不同的div,使用增量ID将每个内容放入自己的div中。 The Problem is, I'm only getting the "second" step, so it's not going through the whole formular. 问题是,我只走了“第二步”,所以它没有遍及整个配方师。

I guess it's because the form of the first page is still there and all have the same id.. Can anyone help me out here please? 我想这是因为首页的形式仍然存在,并且都具有相同的ID。.有人可以在这里帮助我吗?

id of element in document should be unique. document中元素的id应该是唯一的。 Change the duplicate id at html source or using javascript html源或使用javascript更改重复id

success :  function(data) {
      // change duplicate `reg-form` `id` to value
      // corresponding to `.length` of elements having `id`
      // containing `"reg-form"`
      $(data).filter("#reg-form")
      .attr("id", "reg-form-" + $("[id*='reg-form']").length); 
      $("#reg-form").fadeOut(500).hide(function() {
       $(".result").fadeIn(500).show(function() {
        $(".result" + id).append(data);
       });
      });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM