how to display a loading gif when using jquery ui dialog iframe

9 篇文章 0 订阅

I have this snippet of jquery code. I am trying to figure out a way to have a loading gif while this iframe loads. Thanks for any ideas.

var $dialog = $('<div></div>')
.html('<iframe style="border: 0px; " src="/servlet/trainingServlet?method=editDoc&dir=<%=legDir%>&ID=-1" width="100%" height="580"></iframe>')
.dialog({
     autoOpen: false,
     modal: true,
     height: 575,
     width: 680,
     title: 'edit',
     position: [200, 100],
     buttons: {
         Close: function() {
               $( this ).dialog( "close" );
         }
     }
  });
  $dialog.dialog('open');



var iframe = $('<iframe frameborder="0" marginwidth="0" marginheight="0"   width="780"    height="580" allowfullscreen></iframe>');
   iframe.attr("src", "/user/list");
    var dialog = $("<div></div>").append(iframe).appendTo("body").dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        width: "auto",
        height: "auto",
        close: function () {
            iframe.attr("src", "");
        }
    });
    $(".thumb a").on("click", function (e) {
        e.preventDefault();
        var src = $(this).attr("href");
        var title = $(this).attr("data-title");
        var width = $(this).attr("data-width");
        var height = $(this).attr("data-height");
        iframe.attr({
            width: +width,
            height: +height,
            src: src
        });
        dialog.dialog("option", "title", title).dialog("open");
    });


1 Answer 1

up vote 0 down vote accepted

You can reveal a CSS div just after dialog.open() and then have theloadServlet HTML hide it again when it's loaded. Something like:

$dialog.dialog.open();
$("#loading").show()

See jQuery "Please Waiting, Loading..." animation?

 
 
thanks, but this does not really show inside the dialog. I guess thats what i am asking how to do it –  randy Apr 11 '12 at 17:07
 
For it to show inside the dialog, you'll have to have the servlet's output be ...loading, then replaced in the $(document).ready() block. But it sounds like you already know this. You should look into using $.ajax.load() to fetch the servlet. Then you can –  redried Apr 11 '12 at 21:11
 
..sorry... should say....then you can bind events to the start and end of the ajax call. Again,stackoverflow.com/questions/1964839/… -- scroll down to the 2nd answer -- explains this quite well. –  redried Apr 11 '12 at 21:19


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值