Javascript 在表单提交时显示消息,而不是重定向

Javascript 在表单提交时显示消息,而不是重定向,javascript,jquery,forms,Javascript,Jquery,Forms,我有一份非常基本的报名表。我试图显示一条成功消息(在页面上、弹出窗口中、警报中……我没有首选项),而不是重定向到表单发布到的页面(这是当前正在发生的事情) [p:pid]是填充服务器端的系统的变量标记。 示例: 对不起,这里有什么白痴-我对JS/AJAX非常陌生。谢谢 编辑:我无法控制表单发布到的位置(index.php) 苹果公司的这家公司将是一个很好的起点。这是非常容易设置和使用。我自己也用过好几次 这应该让你开始: $(function () { $('form').aja

我有一份非常基本的报名表。我试图显示一条成功消息(在页面上、弹出窗口中、警报中……我没有首选项),而不是重定向到表单发布到的页面(这是当前正在发生的事情)



[p:pid]是填充服务器端的系统的变量标记。
示例:
对不起,这里有什么白痴-我对JS/AJAX非常陌生。谢谢

编辑:我无法控制表单发布到的位置(index.php)

苹果公司的这家公司将是一个很好的起点。这是非常容易设置和使用。我自己也用过好几次

这应该让你开始:

$(function () {
    $('form').ajaxForm({
        // Use this property to specify how your data will
        // look when it's returned (i.e. JSON, XML, HTML,
        // etc). If you aren't returning any data, you can
        // omit this property.
        dataType: ...,
        success: function (res) {
            // Do something in here on success. Depending on your
            // requirements you may or may not have a result
            // returned to you.
        },
        error: function (res) {
            // Do something in here on error. You should always
            // have an error object passed to you that details
            // the error and possibly any returned error text.
        }
    });
});

有关可用选项的完整列表,请参见API参考页。

最简单的方法是向PHP代码添加重定向。保存表单数据后(我假设发生在index.php中),可以添加一行,如:
header('Location:my_success_page.php')
Hi Matt-我很乐意,但我没有编辑index.php的权限。它需要一个解决方案,我可以在你可以启动的页面中实现@user3366357是一个非常酷的用于AJAXing表单的jQuery插件。安装和使用非常简单。我已经用过几十次了…@war10ck这正是我想要的。非常感谢。直到今天下午晚些时候,我才有时间来实现它,但它看起来很像傻瓜(读:me-proof),我看不出有任何理由不能完全按照描述的那样工作。谢谢你帮我把脚伸进新的水域!
$(function () {
    $('form').ajaxForm({
        // Use this property to specify how your data will
        // look when it's returned (i.e. JSON, XML, HTML,
        // etc). If you aren't returning any data, you can
        // omit this property.
        dataType: ...,
        success: function (res) {
            // Do something in here on success. Depending on your
            // requirements you may or may not have a result
            // returned to you.
        },
        error: function (res) {
            // Do something in here on error. You should always
            // have an error object passed to you that details
            // the error and possibly any returned error text.
        }
    });
});