使用jQuery UI Dialog,如何从其他网页加载内容?

时间:2010-10-14 00:56:31

标签: jquery jquery-ui

标题说一切都解决了一件事:我不想在我的网页正文中添加<div id="something"></div>

我在互联网上找到了这个:

var $mklib = $('<div></div>')
        .html('test')
        .dialog({
            title: "Create a library",
            autoOpen: false,
            show: "fade",
            hide: "fade",
            draggable: false,
            resizable: false,
            height: 150,
            width: 300,
            buttons: { "Create": function() {
                $(this).dialog("close"); }
                },      
        });
$( ".open_mklib" ).click(function() {
    $mklib.dialog( "open" );
    return false;
});

但我需要.html('test')'load_that_*****_page.php'

关于主题,我需要创建按钮来发送将在load_that_*****_page.php内的表单......

任何超人救援?

非常感谢!


好的家伙我在互联网上得到它,这是代码,但是当我点击提交时,它不起作用! :P (网址:http://magix-cjquery.com/post/2010/08/01/jquery-ui-dialog-avec-soumission-de-formulaire-ajax

$('.open_mklib').live("click",function(){
        var box_url = "./functions/modal.php";
            var form_url = "./";
        $("#mklib").load(box_url, function() {
                $(this).dialog({
                            title: 'New Library',
                        height: 'auto',
                        width:'auto',
                            resizable: false,
                        modal: true,
                        position: 'center',
                        overlay: {
                                backgroundColor: '#000',
                                opacity: 0.5
                        },
                        buttons: {
                                'Submit': function() {
                                        $("#mklib form").ajaxSubmit({
                                                url: box_url,
                                                type: "post",
                                                error: function(){
                                                        alert("theres an error with AJAX");
                                                },
                                                beforeSubmit:function(){},
                                                success: function(e){}
                                        });
                                        $(this).dialog('close');
                                },
                                'Cancel': function() {
                                        $(this).dialog('close');
                                }
                        }
                });
        });
});

1 个答案:

答案 0 :(得分:0)

这会让你感到高兴吗?从来没有这样做过,但从理论上讲,我认为你必须首先加载你的php,然后在对话框中将其包装成功。

此外,我还在你的收盘中加入了第二个ajax电话。

var $mklib = $('<div></div>')
    .ajax({type: "GET", url: blah_blah.php,  dataType: "script", success: function(){
      .dialog({
          title: "Create a library",
          autoOpen: false,
          show: "fade",
          hide: "fade",
          draggable: false,
          resizable: false,
          height: 150,
          width: 300,
          buttons: { "Create": function() {
              $.ajax({type: "POST", url: "whever_this_goes.php", data: $("#yourForm").serialize(), success: function(){$(this).dialog("close") })}
              },      
      }); 
   }
});

$( ".open_mklib" ).click(function() {
    $mklib.dialog( "open" );
    return false;
});