Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 为什么在提交表单后隐藏引导模式?_Jquery_Twitter Bootstrap - Fatal编程技术网

Jquery 为什么在提交表单后隐藏引导模式?

Jquery 为什么在提交表单后隐藏引导模式?,jquery,twitter-bootstrap,Jquery,Twitter Bootstrap,我有下面的代码,我正在使用bootstap模式(一个弹出对话框),当我单击“添加”按钮时,将提交表单,就像jquery代码显示的那样。但是我不知道为什么表单提交后,模态会自动隐藏,如何控制它使表单提交后仍然存在 $("#personDialogAddPersonBtn").click( function(){ $("#documentFile").attr("disabled", true); $("

我有下面的代码,我正在使用bootstap模式(一个弹出对话框),当我单击“添加”按钮时,将提交表单,就像jquery代码显示的那样。但是我不知道为什么表单提交后,模态会自动隐藏,如何控制它使表单提交后仍然存在

    $("#personDialogAddPersonBtn").click(
            function(){
                $("#documentFile").attr("disabled", true);
                $("#announcementForm").attr("action","${contextPath}/announcement/addAnnoPubToPerson.action");
                $("#announcementForm").submit();
            }       
        );


<div id="addPersonDialog"class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="Add Person" aria-hidden="true">

 ...

 <div class="modal-footer">
  <a class="bt bt-pane b1" id="personDialogAddPersonBtn">Add</a>
  <a class="bt" id="personDialogCloseBtn">Close</a>
 </div>
$(“#personDialogAddPersonBtn”)。单击(
函数(){
$(“#documentFile”).attr(“已禁用”,true);
$(“#announcementForm”).attr(“操作”,“${contextPath}/announcement/addAnnoPubToPerson.action”);
$(“#公告表”).submit();
}       
);
...
添加
接近

您可能必须使用
event.preventDefault()
,并且您可能希望通过ajax提交表单:

$("#announcementForm").submit(function(e){
    e.preventDefault()
    $("#documentFile").attr("disabled", true);
    $.post( "${contextPath}/announcement/addAnnoPubToPerson.action", $(this).serialize() ).done(function(data) {
        //success
    })
    .fail(function() {
        //error
    });
});
使用.ajax()异步发送帖子并避免刷新

如果您的应用程序能够很好地处理JSON对象,您可以序列化表单,创建JSON对象并将其发送到应用程序

$('#personDialogAddPersonBtn').click(function() {    

    data = $("#announcementForm").serializeObject();
    data = JSON.stringify(data);

    $.ajax({
        url: '${contextPath}/announcement/addAnnoPubToPerson.action'
        type: 'POST',
        data: data,
        contentType: 'application/json;charset=UTF-8',
        cache:false,
        success: function (response) {
            alert('Form submitted')
        },
        error: function(response){
            alert('Error submitting form)
        }
    });

});

$.fn.serializeObject = function()
    {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };

您是通过常规POST请求提交表单还是使用AJAX POST请求。看起来你正在做一个常规的POST请求,这样看起来会重新加载页面。很可能你的页面正在刷新,因为你似乎没有通过ajax提交。