简体   繁体   English

jQuery将数据发布到下一页

[英]jQuery Post data to next page

I'm programming a registration page where the user first selects one of three options in the first page and only then can move onto the second page because it displays content that is dependent on the previous selection. 我正在编写一个注册页面,用户首先在第一页中选择三个选项之一,然后才能移动到第二页,因为它显示的内容取决于之前的选择。 So this is my code: 所以这是我的代码:

<script>
$(document).ready(function(e) {
    $("form").submit(function() {
        var data= $(this).serialize();
        $.post("/Registration_1.php",data);
        alert(data);
    });
});
</script>

<form id="frmtype1" name="frmtype1" method="post">
<input type="radio" name="Reg_type" value="1"/> option 1 <br/>
<input type="radio" name="Reg_type" value="2"/> option 2<br/>
<input type="radio" name="Reg_type" value="3"/> option 3 <br/>
<input type="submit" name="Submit" value="Submit" />
</form>

The problem is that after selecting an option and clicking submit it just stays on page 1. The alert displays the data, which is all correct but it just wont move to the next page. 问题是,在选择一个选项并单击提交后,它只停留在第1页。警报显示数据,这一切都正确但它不会移动到下一页。 I'm brand new to jquery so i don't know if the $.post is syntactically correct. 我是jquery的新手,所以我不知道$ .post在语法上是否正确。 Can anyone see what the problem here is? 任何人都可以看到这里的问题是什么? Why won't it go to the next page? 为什么不进入下一页? Thank you 谢谢

Yo mate you need to define one more function which handles the success event of your post method. 哟伙计你需要再定义一个处理post方法成功事件的函数。 When your post is completed succesfully then you can change the URL like SomeKittens showed you. 当您的帖子成功完成后,您可以更改SomeKittens向您显示的URL。

$.post("/Registration_1.php",data,function(response){
     window.location = ...
});

Do specify the action in the form like : action="your url" 请在表单中指定操作,例如: action =“your url”

for eg: 例如:

<body>
    <form id="form1" action="http://stackoverflow.com/" method="post">
        <input type="radio" name="Reg_type" value="1"/> option 1 <br/>
        <input type="radio" name="Reg_type" value="2"/> option 2<br/>
        <input type="radio" name="Reg_type" value="3"/> option 3 <br/>
        <input type="submit" id="s" name="Submit" value="Submit" />
    </form>
</body>

Modified script: 修改后的脚本

   $(document).ready(function () {
        $('input').on('click', function () {
            window.location('http://stackoverflow.com/');
        });
    });

hope this helps :) 希望这可以帮助 :)

The problem is that $.post is sending the data, but not redirecting the user. 问题是$.post正在发送数据,但不会重定向用户。

Here's a tutorial on how to redirect the user. 这是一个关于如何重定向用户的教程。

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

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