簡體   English   中英

在同一頁面提交表單時如何打開另一頁面

[英]how to open another page when form submitted at the same page

我在彈出窗口中有一張注冊表。 我想當表單在div框中的“錯誤-ajax”下打開的div框中以錯誤打印的形式提交響應時。 我的問題是提交表單時,第二個頁面不在該div中加載。

這是我的代碼:

<html>
<head>
<script type="text/javascript" src="js/jquery-1.7.2.min_1.js"></script>
</head>
<body>
<div class="main">
<!--div 1-->
<div class="comment1">
<p>YOUR COMMENT</p>
<div class="reply">
 reply
</div>
</div>
<!--End div 1-->

<div class="repetable">
<form class="formnazar-user">
<input type="textbox" />
</form>
</div>
<script>
$(function() {
 $(".repetable").hide();
 $(".reply").bind("click", function() {
 $(".repetable").hide();
 $(".repetable").slideDown("slow")
 $("#nazar").slideUp("slow");
});
 });
</script>


<!--div 2-->
<div class="comment1">
<p>YOUR COMMENT2</p>
<div class="reply">
reply
</div>
</div>
<!--End div 2-->

<div class="repetable">
<form class="formnazar-user">
<input type="textbox" />
</form>
</div>
</div>

</body>

</html>

取而代之的是,您必須將表單作為ajax請求提交。 使用數據ans $(“#form”)。serialze(),在收到響應后對div元素進行必要的更新

$.post( "second-page.bc", $( "#form-1" ).serialize() )
    .done(function(data) {
        //update your div with data
    })
    .fail(function() {
        alert( "error" );
    });

您可以使用window.open()將頁面重定向到另一個頁面。 它有兩個參數; 首先是您要重定向的位置,其次是目標。 例如:

<script type="text/javascript"> 
window.open('success.php','_self'); 
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM