duanfa2014 2016-12-07 11:04
浏览 99
已采纳

在窗口加载时显示加载图像,直到DomContentLoaded

I have a php page that requires another php page, the page seems to take very long to load so I decided to have a loading image, problem is the image appears almost when the whole page loads instead of appearing when the page stsrts loading, how can I solve this?

my code is as follows:

   <?php  
    echo '<div id="mm">mm</div>'; 
   require_once( 'includes/xxxxxxxxxxxx.php' ); ?>
  <html>
  <head>
  <title>myiframe</title>
  <script  src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js">                  
   </script>
   <scriptsrc="http://cdnjs.cloudflare.com/ajax/l
   ibs/modernizr/2.8.2/modernizr.js"></script>

    <script tyep="text/javascript">
    $(window).load(function() {
    // Animate loader off screen
    $("#mm").fadeOut("slow");
    });
    </script>
    <head>

    <body>
    </body>
    </html>
  • 写回答

3条回答 默认 最新

  • dongyi1441 2016-12-07 11:09
    关注

    PHP runs before the DOM is visible (as the DOM is in the client-side, and PHP is in the server side. When you see the page, PHP is done), so when the requiring taking place you are not seeing anything (server is still running the PHP - DOM is not visible).

    You'll have to modify the architecture. For example, first load the page without xxxxxxxxxxxx.php and later get xxxxxxxxxxxx.php content with an AJAX call - when firing the AJAX to get the page, display the loading image.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行