Javascript 如何从对话框中重新加载jQuery对话框?

Javascript 如何从对话框中重新加载jQuery对话框?,javascript,jquery,jquery-ui,jquery-dialog,Javascript,Jquery,Jquery Ui,Jquery Dialog,我在jQuery对话框中加载一个页面。ajax命令完成后,我希望能够在jQuery对话框中重新加载相同的页面。如何从对话框中加载的页面中重新加载jQuery对话框 父页面(Blah.aspx): 函数视图_对话框(){ $('#dialog').load('blah2.aspx').dialog({ 标题:"测试",, 情态:'真', 宽度:“80%”, 高度:'740', 位置:'中间', 显示“比例”, 隐藏:“缩放”, 缓存:false}); } 对话框内容页(blah2.aspx):

我在jQuery
对话框中加载一个页面。ajax命令完成后,我希望能够在jQuery
对话框中重新加载相同的页面。如何从
对话框
中加载的页面中重新加载jQuery
对话框

父页面(Blah.aspx):


函数视图_对话框(){
$('#dialog').load('blah2.aspx').dialog({
标题:"测试",,
情态:'真',
宽度:“80%”,
高度:'740',
位置:'中间',
显示“比例”,
隐藏:“缩放”,
缓存:false});
}
对话框内容页(blah2.aspx):


$(文档).ready(函数(){
函数doit(){
var请求=$.ajax({
url:“someurl”,
数据类型:“JSON”,
数据:{
a:‘有价值’
}
});
request.done(函数(){
//再次调用blah2.aspx刷新当前对话框
});
}       

您正在将另一个页面的内容加载到当前页面的对话框容器中,因此这里实际上只有一个页面。我建议仅从对话框源页面加载部分html(无
标记)

因此,您可以销毁对话框并重新创建它以重新加载对话框内容:

function reload_dialog()
{
    $('#dialog').dialog('destroy');
    view_dialog();
}

function view_dialog() {
    $('#dialog').load('blah2.aspx').dialog({
        title: 'test' ,
        modal: 'true',
        width: '80%',
        height: '740',
        position: 'center',
        show: 'scale',
        hide: 'scale',
        cache: false });
}
或者,您可以重新加载整个页面

window.location.reload();

您可以在jQuery中扩展ui.dialog,如下所示:

// Note the "url" option.
function view_dialog() {
    $('#dialog').dialog({
        url:'blah2.aspx',
        title: 'test' ,
        modal: 'true',
        width: '80%',
        height: '740',
        position: 'center',
        show: 'scale',
        hide: 'scale',
        cache: false });
}


// refresh:
$('#dialog').dialog("refresh");
$.ui.dialog.prototype.options.url;//定义新选项“url”

现在,您可以替换整个对话框“创建”,使其自动加载url并定义新的“刷新”选项:

您的最终函数如下所示:

// Note the "url" option.
function view_dialog() {
    $('#dialog').dialog({
        url:'blah2.aspx',
        title: 'test' ,
        modal: 'true',
        width: '80%',
        height: '740',
        position: 'center',
        show: 'scale',
        hide: 'scale',
        cache: false });
}


// refresh:
$('#dialog').dialog("refresh");

你可以在这把小提琴上看到最后的代码:

谢谢你!我知道已经过去4年了,但是你的代码帮了我很大的忙!
    // Replace the _create event
    var orig_create = $.ui.dialog.prototype._create;
    $.ui.dialog.prototype._create = function(){
        orig_create.apply(this,arguments);
        var self = this;
        if(this.options.url!=''){
            self.element.load(self.options.url); // auto load the url selected
        };
    };

    $.widget( "ui.dialog", $.ui.dialog, {
        refresh: function() {
            if(this.options.url!=''){
                this.element.load(this.options.url);
            }
        }
    });
// Note the "url" option.
function view_dialog() {
    $('#dialog').dialog({
        url:'blah2.aspx',
        title: 'test' ,
        modal: 'true',
        width: '80%',
        height: '740',
        position: 'center',
        show: 'scale',
        hide: 'scale',
        cache: false });
}


// refresh:
$('#dialog').dialog("refresh");