Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
Ajax jQuery用户界面对话框赢得';无法在Internet Explorer中打开_Ajax_Jquery Ui_Internet Explorer_Dialog - Fatal编程技术网

Ajax jQuery用户界面对话框赢得';无法在Internet Explorer中打开

Ajax jQuery用户界面对话框赢得';无法在Internet Explorer中打开,ajax,jquery-ui,internet-explorer,dialog,Ajax,Jquery Ui,Internet Explorer,Dialog,我有一个jQuery UI对话框: $("#dialog").dialog({ modal: true, closeOnEscape: false, resizable: false, autoOpen: false, open: function() { $(".ui-dialog-titlebar").hide(); } }); 我正试图在AJAX调用之前打开此对话框。它使用Firefox工作,但在IE中它不会打开,除非我打开

我有一个jQuery UI对话框:

$("#dialog").dialog({
    modal: true,
    closeOnEscape: false,
    resizable: false,
    autoOpen: false,
    open: function() {
        $(".ui-dialog-titlebar").hide();
    }
});
我正试图在AJAX调用之前打开此对话框。它使用Firefox工作,但在IE中它不会打开,除非我打开对话框后立即发出
警报。有人能告诉我可能是什么问题吗?我正在使用以下代码:

$("button").click(function() {
    $("#dialog").dialog('open');
    //alert('test'); //if I put this alert, the dialog will open
    $.ajax({
        type: "POST",
        url: "testing.txt",
        async: false,
        dataType: "text",
        success: function(returnText) {
            $("#dialog").dialog('close');
            $("#textarea").text(returnText);
        },
        error: function() {
            $("#dialog").dialog('close');
        }
    });
});

open
事件由于潜在的动画而异步完成,因此可能发生的情况是,由于IE的缓慢JavaScript解释,在
success
error
回调中关闭对话框的代码(也是异步的)执行时离
open
足够近,以至于您没有注意到对话框被打开。我猜您的AJAX调用将很快完成

解决这个问题的一种方法是将AJAX调用放在
setTimeout
块中

$("button").click(function() {
    $("#dialog").dialog('open');

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: "testing.txt",
            async: false,
            dataType: "text",
            success: function(returnText) {
                $("#dialog").dialog('close');
                $("#textarea").text(returnText);
            },
            error: function() {
                $("#dialog").dialog('close');
            }
        });
    }, 1);
});

这将简单地对
$.ajax
调用进行排队,这将允许
打开
事件完成。John Resig很好地解释了为什么这种事情会在这里发生。

由于潜在的动画,
打开
事件异步完成,因此可能发生的情况是,由于IE的缓慢JavaScript解释,在
成功
错误
回调中关闭对话框的代码(它们也是异步的)执行时离
open
足够近,以至于您没有注意到对话框被打开。我猜您的AJAX调用很快就完成了

解决这个问题的一种方法是将AJAX调用放在
setTimeout
块中

$("button").click(function() {
    $("#dialog").dialog('open');

    setTimeout(function() {
        $.ajax({
            type: "POST",
            url: "testing.txt",
            async: false,
            dataType: "text",
            success: function(returnText) {
                $("#dialog").dialog('close');
                $("#textarea").text(returnText);
            },
            error: function() {
                $("#dialog").dialog('close');
            }
        });
    }, 1);
});

这将简单地将
$.ajax
调用排队,这将允许
打开
事件完成。John Resig对这类事情在这里工作的原因有一个很好的描述-。

解决这个问题的另一种方法是将“dialog.open”部分放在mousedown事件中,而不是单击。这样你仍然可以做IE(8)的事情不喜欢将其放入设置超时,例如下载文件。

解决此问题的另一种方法是将“dialog.open”部分放入mousedown事件中,而不是单击。这样,您仍然可以执行IE(8)中的操作不喜欢将其放入setTimeout,比如下载文件。

谢谢,这解决了我的问题!!我的弹出窗口中也有一个GIF动画,但它不起作用。你知道这个问题可能是什么吗?没有理由不起作用。你能看看Chrome的开发工具中的网络选项卡或Firebug中的网络选项卡,看看正在正确请求和返回图像?这可能是需要预取图像的问题,您可以通过调用
new image('path/to/myImage.png')进行预取;
在JavaScript早期的某个地方。谢谢,这解决了我的问题!!我的弹出窗口中也有一个GIF动画,但它不起作用。你知道这个问题可能是什么吗?没有理由不起作用。你能看看Chrome的开发工具中的“网络”选项卡或Firebug中的“网络”选项卡,看看图像是否被请求并被删除吗是否正确转换?可能是需要预取图像的问题,您可以通过调用JavaScript早期的某个地方的
new image('path/to/myImage.png');
来预取图像。