表单提交后jquery重定向

时间:2014-04-23 11:46:41

标签: jquery codeigniter-2

我使用codeignitor。以下是我用于登录表单验证的jquery代码。

            $("#login_form").validate({
                errorPlacement: function(error, element) { },// Disable error messages
                debug:true,
                rules: {
                    username: 
                    {
                        required: true,
                        remote: 
                        {
                            url: "http://localhost/my_site/index_page/validate_username_password",
                            type: "post",
                            data: {
                            password: function(){ return $("#password").val(); } //Password is sent alongside the username
                            }
                        }
                    },
                password:{required:true}
                },
                highlight: function(username, errorClass) 
                {
                    $(username).fadeOut(function() 
                    {
                        $(username).fadeIn();
                    });
                },
                submitHandler: function(form) // CALLED ON SUCCESSFUL VALIDATION
                {
                    window.location.replace='http://localhost/my_site/index_page';
                }
            });

通过此代码,在成功验证后,我希望我的页面可以重定向到

http://localhost/my_site/index_page

但事实并非如此。

我使用codeignitor。

3 个答案:

答案 0 :(得分:1)

window.location.replace()是一个函数,用它作为:

window.location.replace('http://localhost/my_site/index_page');

答案 1 :(得分:0)

检查this link并查看建议的解决方案。

在得出任何结论之前,请确保submitHandler: function(form) {}确实被解雇了。

答案 2 :(得分:0)

试试这个:

使用

document.location='http://localhost/my_site/index_page';

而不是

window.location.replace='http://localhost/my_site/index_page';
你的代码中的

......