Javascript 如何将表单提交操作从显示警报弹出窗口更改为重定向到新页面?

Javascript 如何将表单提交操作从显示警报弹出窗口更改为重定向到新页面?,javascript,redirect,contact-form,Javascript,Redirect,Contact Form,我正在尝试解决其他人创建的一些问题(从来都不是一个有趣的潜在客户),并希望消除一个弹出的警报,让用户在提交表单后重定向到另一个页面。。。我搜索了网页,找到了几个可能的替代方案,但我也不想破坏页面,因为我在PHP疑难解答方面没有太多经验。。。我猜,这是一个非常简单的101级问题,但要提前表示感谢。。。以下是相关代码: jQuery("form#commentform input#submit").click(function(event) { event.preventDe

我正在尝试解决其他人创建的一些问题(从来都不是一个有趣的潜在客户),并希望消除一个弹出的警报,让用户在提交表单后重定向到另一个页面。。。我搜索了网页,找到了几个可能的替代方案,但我也不想破坏页面,因为我在PHP疑难解答方面没有太多经验。。。我猜,这是一个非常简单的101级问题,但要提前表示感谢。。。以下是相关代码:

    jQuery("form#commentform input#submit").click(function(event) {
        event.preventDefault();

        var name = jQuery("form#commentform input#author").val();
        if(name=="") {
            alert("Name cannot be empty!");
            jQuery("form#commentform input#author").focus();
            return false;   
        }

        var email = jQuery("form#commentform input#email").val();
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        var email_test= pattern.test(email);  

        if (email == "" || email_test == false) {
            alert('Valid email address is required!');
            jQuery("form#commentform input#email").focus();
            return false;
        }

        var phone = jQuery("form#commentform input#url").val();
        var comment = jQuery("form#commentform textarea#comment").val();

        jQuery.get('http://theenergyclub.com/wp-content/themes/EnergyClub/formPost.php', {type:'guestpass', name:name, email:email, phone:phone, comment:comment, rnDnum:Math.random()}, function(data) {
            alert('We have received your request. Thank you!');

您可以尝试替换最后一行

alert('We have received your request. Thank you!');


您只需更改
警报('我们已收到您的请求。谢谢!')
window.location=''
其中
是您希望将用户重新定向到的URL。

如果有重定向,那么直接使用表单提交不是更好吗?是的,这会更好,但我不确定Craig是想转到提交页面还是其他页面。我还注意到一些非html格式的参数,如
rnDnum:Math.random()
window.location = "http://example.com/"