如何从表单操作重定向其他URL

时间:2016-08-30 10:11:20

标签: javascript jquery ajax

我创建了一个表单,在提交名称时,我的网址被重定向,但我想在表单操作后,它应该重定向到我的移动验证页面。放完代码之后,我想让它显示优惠页面。我无法写ajax。我的功能没有被调用。这是我到现在为止所尝试的 http://plnkr.co/edit/3DA7YGb58BgcVcD0d10f?p=preview

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css">
        <script src="script.js"></script>
    </head>
    <body>
        <form name="msform"  action="another.html" method="post" id="msform">
            <input name="name" type="text" placeholder="First Name" />
            <input class="bl" id="submitbl" type="submit" value="Submit" />
        </form>
        <script type="text/javascript">
            $("#submitbl").click(function(){
                if($("#msform").valid() === true) {
                    var name  = $('input[name|="name"]').val();
                    //use ajax to run the check
                    $.ajax({
                        type : 'POST',
                        url  : 'mobile.html',
                        success: function(responseText){
                            resp = responseText.trim().substring(14);
                            if(resp == 'qualified') {
                                url_redirect({url: "offer.html",
                                    method: "post",
                                    data: { "fname": name }
                                });
                            }
                        }
                    });
                }
            });
        </script>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

为此您可以执行以下操作:

编写一个jQuery onsubmit函数并触发提交按钮的click事件。

$("#msform").on('submit',function(){
 $("#submitbl").trigger('click');
});

通过ajax和成功功能重定向到mobile.html

提交表单
相关问题