【问题标题】:Jquery AJAX form POST submit issueJquery AJAX表单POST提交问题
【发布时间】:2014-08-15 11:03:59
【问题描述】:

我有以下 AJAX 代码,如果成功,我想使用 post 方法重定向,所以我有一个虚拟表单 (id="form-post-change-tab") 并通过 post 重定向到 ./landing。

问题是这个函数立即提交表单 $(#form-post-change-tab).submit();而不是调用 AJAX 请求并重定向成功方法。

有什么想法吗?

$(function() {
    $("#form-CreateNewTab").submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: "/home/create-tab",
            data: $('#form-CreateNewTab').serialize(),

            success: function(msg){
                //alert(msg);
                $('#tabID').val(msg);
                $(#form-post-change-tab).submit();
            },

            error: function(){
                alert("newtab failure");
            }

        });
    });
});




<form id="form-post-change-tab" action="./landing" method="post">
    <input id="tabID" type="hidden" value="">
</form>

【问题讨论】:

    标签: jquery ajax html


    【解决方案1】:

    那是因为您的表单 ID 没有引号!

    $(#form-post-change-tab).submit()
    

    需要报价

    $('#form-post-change-tab').submit() 
    

    【讨论】:

    • "#form-CreateNewTab" 实际上是一个不同的表单(模式引导对话框表单),当我提交它调用“#form-CreateNewTab”函数时
    • 当!!!你搞定了……我在 $(#form-post-change-tab).submit() 中没有引号……谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 2011-03-28
    • 1970-01-01
    • 2021-05-13
    • 2013-08-24
    • 2023-03-04
    相关资源
    最近更新 更多