使用提交按钮后,我们如何在同一页面上以不同的形式保留在同一页面上?

时间:2014-03-25 04:57:01

标签: php jquery ajax

我想构建一个表单构建器,其中整个html根据其表单id来自数据库。

我想问的是,当我们点击提交按钮时,表单ID将如何增加,以便我们在同一页面上获得新表单。我怎么能这样做?

3 个答案:

答案 0 :(得分:2)

<html>
<head>
<script>

$.ajax({
                    type: "POST",
                    url: path ,
                    data: {id:$('#id').val()+1},
                    success: function(res) {
                        $('#varible_html').html("");   
                         $('#varible_html').html(res);    // res contain the html that you want to set on page
                    },
                    error:function (res)
                    {
                        alert(res);  
                    }
                }); 
     </script>
</head>
<body>
<form id="test" name="test">
<input type="hidden" id="id" value = "<?=$id?>">
<div id="varible_html">
</div>
<input type="button" onclick="sub()" id="btn">
</form>
</body>
</html>  

答案 1 :(得分:0)

您可以使用Javascript或JQuery。添加处理程序以提交点击按钮。

使用ajax调用处理数据,然后隐藏当前表单并显示第二个表单。

...开始

form1 - 显示为真

form2 - 显示为false

onclick处理程序

  • 使用ajax处理数据
  • form1 - 显示为false
  • form2 - 显示 真实。

如果您需要更多信息,请与我们联系。

答案 2 :(得分:0)

这很简单。首先创建像这样的HTML

<form id="form1">
    ....
    <button type="submit" id="test">Submit</button>
</form>

现在为JS部分

$("#test").on("click", function(event) {
    event.preventDefault();
    $.post(URL, form1.serialize(), function(data) {
        //Create new form with the server data here.
    });
});

请注意,这是暂定代码,您可能需要针对您的用例进行优化。

相关问题