Jquery Ajax在单击关闭按钮后触发模式

Jquery Ajax在单击关闭按钮后触发模式,jquery,ajax,twitter-bootstrap,Jquery,Ajax,Twitter Bootstrap,我有一个模式,当点击Submit时,它会做一篇ajax文章,但是现在我想选择关闭模式,但只要我点击close,它仍然会做ajax文章。我不想在点击“关闭”按钮时发布ajax帖子。我不知道如何处理这种情况 模态 不要将ajax调用绑定到on('hidden')事件,而是绑定到submit按钮上的click事件 [更新] (我不知道模态插件,但它应该是这样的:) 然后,您应该为ajax post创建自己的函数,并通过按钮将其绑定到onclick事件: <input type="Button"

我有一个模式,当点击Submit时,它会做一篇ajax文章,但是现在我想选择关闭模式,但只要我点击close,它仍然会做ajax文章。我不想在点击“关闭”按钮时发布ajax帖子。我不知道如何处理这种情况

模态


不要将ajax调用绑定到on('hidden')事件,而是绑定到submit按钮上的click事件

[更新] (我不知道模态插件,但它应该是这样的:)


然后,您应该为ajax post创建自己的函数,并通过按钮将其绑定到onclick事件:

<input type="Button" value="Done" onclick="ajaxCall()" />

我已经修复了我的模式,我对jquery做了一些修改,现在它工作得很好

$("#ModelView").modal("show").on(
    //$(document).on("click", '#btnDoneEdit', function (e) {
    $('#btnDoneEdit').click(function (e) {
                        // e.preventDefault();
                        alert("Hi");
                        //if (a.target.localName != 'div')
                        //    return;

                        var d = {
                            id: 0,
                            SubjectId: $("#subjectSelect").val(),
                            ClientId: $("#clientSelect").val(),
                            From: f + " " + $("#from").val(),
                            Till: f + " " + $("#till").val(),
                            DontCount: $("#dontCount").is(":checked"),
                            Type: $("#typeSelect").val(),
                            LessonCounter: $("#SelectLessonCounter").val()
                        }

                        $.ajax({
                            type: "POST",
                            url: "Api/UpdateTimeTable.ashx",
                            data: JSON.stringify(d),
                            success: function (response, status, xhr) {
                                var ct = xhr.getResponseHeader("content-type") || "";
                                if (ct.indexOf('json') > -1) {
                                    window.location = window.location;
                                }
                                if (ct.indexOf('text') > -1) {
                                    alert(response);
                                    window.location = window.location;
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                alert("There seems to be a problem. " + errorThrown);
                            }
                        });

                    })
                );

一个特定模态插件的链接会很有用。你能给我举个例子吗?我仍然是一个新手,刚刚又看了一遍代码,它应该是bind on('hidden')。该事件将显示模式,但现在如果我单击关闭模式,它不应该执行ajax帖子,当我单击“完成”时,它应该执行ajax帖子。非常感谢,它可以工作,但现在当我单击“完成”时,我的模式隐藏,并且只有在我第二次提交ajax时才会被调用。这可能是什么原因呢?请看我的编辑,我将“隐藏”部分移到了ajax调用的success函数中。我已经按照你的建议移动了它,但问题仍然没有改变。ajax只在第二次尝试时才开火。如果我单击“完成”,它会隐藏,那么我必须让它再次出现,然后只调用ajax事件。
$("#ModelView").modal("show");

             /*EDIT*/ 
            $(document).on( "click", '#btnDoneEdit', function(e){
              e.preventDefault();
            /*EDIT end */


                var d = {
                    id: 0,
                    SubjectId: $("#subjectSelect").val(),
                    ClientId: $("#clientSelect").val(),
                    From: f + " " + $("#from").val(),
                    Till: f + " " + $("#till").val(),
                    DontCount: $("#dontCount").is(":checked"),
                    Type: $("#typeSelect").val(),
                    LessonCounter: $("#SelectLessonCounter").val()
                }


                $.ajax({
                    type: "POST",
                    url: "Api/UpdateTimeTable.ashx",
                    data: JSON.stringify(d),
                    success: function (response, status, xhr) {
                        var ct = xhr.getResponseHeader("content-type") || "";
                        if (ct.indexOf('json') > -1) {
                            window.location = window.location;
                        }
                        if (ct.indexOf('text') > -1) {
                            alert(response);
                            window.location = window.location;
                        }
                    $("#ModelView").modal("hide");

                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert("There seems to be a problem. " + errorThrown);
                    }
                }); 


            });
<input type="Button" value="Done" onclick="ajaxCall()" />
function ajaxCall()
{
$.ajax({...)};
}
$("#ModelView").modal("show").on(
    //$(document).on("click", '#btnDoneEdit', function (e) {
    $('#btnDoneEdit').click(function (e) {
                        // e.preventDefault();
                        alert("Hi");
                        //if (a.target.localName != 'div')
                        //    return;

                        var d = {
                            id: 0,
                            SubjectId: $("#subjectSelect").val(),
                            ClientId: $("#clientSelect").val(),
                            From: f + " " + $("#from").val(),
                            Till: f + " " + $("#till").val(),
                            DontCount: $("#dontCount").is(":checked"),
                            Type: $("#typeSelect").val(),
                            LessonCounter: $("#SelectLessonCounter").val()
                        }

                        $.ajax({
                            type: "POST",
                            url: "Api/UpdateTimeTable.ashx",
                            data: JSON.stringify(d),
                            success: function (response, status, xhr) {
                                var ct = xhr.getResponseHeader("content-type") || "";
                                if (ct.indexOf('json') > -1) {
                                    window.location = window.location;
                                }
                                if (ct.indexOf('text') > -1) {
                                    alert(response);
                                    window.location = window.location;
                                }
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                alert("There seems to be a problem. " + errorThrown);
                            }
                        });

                    })
                );