Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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
Javascript jQuery:AJAX提交后关闭对话框_Javascript_Jquery_Ajax_Forms_Jquery Ui - Fatal编程技术网

Javascript jQuery:AJAX提交后关闭对话框

Javascript jQuery:AJAX提交后关闭对话框,javascript,jquery,ajax,forms,jquery-ui,Javascript,Jquery,Ajax,Forms,Jquery Ui,通过AJAX提交后,我希望关闭表单。我在这里查阅了谷歌和一些老话题,但什么也找不到!我有一个javascript函数来显示我的表单,还有一个函数用于ajax请求,我想我应该获取OpenModalWindow的实例,然后关闭它,但我不确定 下面是显示表单窗口的代码 $(function (){ function handler() { if (this.readyState == this.DONE) { if (this.status == 200 && this.res

通过AJAX提交后,我希望关闭表单。我在这里查阅了谷歌和一些老话题,但什么也找不到!我有一个javascript函数来显示我的表单,还有一个函数用于ajax请求,我想我应该获取OpenModalWindow的实例,然后关闭它,但我不确定

下面是显示表单窗口的代码

$(function (){
function handler() {
if (this.readyState == this.DONE) {
    if (this.status == 200 && this.responseText != null) {
        $("#modal").html(this.responseText);
        return;
    }
    console.log('Something went wrong! Status = ' + this.status);
 }
}

var client = new XMLHttpRequest();
client.onreadystatechange = handler;

$(document).ready(function () {
   $(document).on('click','.showModal',function(event) {
    client.open("GET", $(this).attr("href"),true);
    client.send();
var dialog;
dialog =   $("#modal").dialog({
        autoOpen:true,
        width: 400,
        height: 450,
        modal: true,
        /*close: function () {
            $("#modal").html('');
        }*/
        buttons: [{ 
           text: "Cancelar", 
           click: function() { 
             dialog.dialog("close"); 
           }
        }],
        close: function () {
            $("#modal").html('');
        }

    });
    return false;
 });

});
});    
下面是我通过AJAX发送数据的代码,并尝试用以下代码关闭窗口:

$(function(){
$("#y").on('click',function(event){
     event.preventDefault();
     var id = $("input[name=id]").val();
     var action = 'del';
     $.post("album/ajax",{
          action : action,
          id     : id
        },
        function(data){
          if(data.response == true){
            if(action == 'del') {
              var table = $('#table');
              table.find('tr').each(function(indice){
              $(this).find('td').each(function(indice){
                if($(this).text() == ''){
                var valor = $(this).find('input[name=cod]').val();
                 if(valor == id){
                    $(this).closest('tr').remove();
                    /*var dialog;
                    dialog =   $("#modal").dialog();
                    dialog.closest(".ui-dialog-content").dialog("close");
                    dialog.dialog("close");*/
                  }
                }
             });
            });
           }
         } else {
               alert("Nao foi possivel deletar!");

         }
        },'json');

 });
});

试试$(“模态”)对话框(“关闭”)

我已经看过了,但没有人为我工作。我仍然有同样的问题。我这样做了,我得到了这个错误消息错误:无法在初始化之前调用对话框上的方法;试图调用方法“close”,我不太懂你的代码。这一切都发生在一页上吗?所以你称之为$(“#modal”).dialog(“close”);紧跟在$(this).closest('tr').remove()之后?我在测试,但是是的,它发生在我所有的modals对话框中,我只是声明我的var对话框是全局的,它解决了,但我不确定这是否是最好的方法!