在步骤 1中单击按钮时,
你插入到对应的表中,得到插入的id
将插入的 id 值保存在表单中的某个隐藏类型中。
在步骤 2中单击按钮时,
- 您需要使用您在表单中保存的 id 更新插入的表行数据中的相应列及其值
继续相同的过程,直到完成所有步骤。
<script>
$(document).ready(function() {
$("#next").click(function() {
var currentStep = $('#currentStep').val(); // based on the step you need use some switch or conditional block to pass data and store it accordingly.
// insertedId ==0 means you need to insert into table, if it not you need update the column in table
var formdata = {insertedId:$("#insertedId").val(),currentStep:currentStep, first:$("#first").val()};
$.ajax({
type: "POST",
url: "form.php",
dataType:'json',
data: formdata
})
.done(function( data ) {
var NextStep =parseInt(currentStep)+1;
$("#currentStep").val(NextStep);
$("#insertedId").val(data.insertedId);
$("#step"+currentStep).hide();
$("#step"+NextStep).show();
});
});
});
</script>
HTML:
<div id="step1">Step 1:
<input type="text" name="first" id="first" value="">
</div>
<div id="step2" style="display:none;">Step 2:
<input type="text" name="last" id="last" value="">
</div>
<input type="hidden" name="insertedId" id="insertedId">
<input type="hidden" name="currentStep" id="currentStep" value="1">
<button id="next">Next</button>