简体   繁体   English

.load方法花费的时间太长

[英].load method takes too long

What I'm doing is loading different content into a div each button. 我正在做的是将不同的内容加载到div每个按钮中。 The code I'm using to do so: 我正在这样做的代码:

$(function(){
    $('#galleries').hide().load("letters/index.php", function(){
        $(this).slideDown(1);
        $(this).slideUp(1);  
        $(this).hide();
        $(this).slideDown(1500);/* or fadeIn() or any other effect*/
        document.getElementById("data").style.display = 'none';
    });
});

This is an example of one code. 这是一个代码的示例。 I got another 8 like this, but I'm loading into #galleries a different php page everytime. 我又得到了8个这样的代码,但是每次我都在#galleries中加载一个不同的php页面。

My problem is, it takes ages to load the second page. 我的问题是,加载第二页需要花费很多时间。 For example, on my first click on any button, it takes a second to load everything, doesn't matter what content it has. 例如,在我第一次点击任何按钮时,加载所有内容都需要花费一秒钟,无论它包含什么内容。 But whenever I press on another button to load another page, I have to wait for about 3-5seconds, and when I'm waiting, it shows nothing, no div is being shown, just the background. 但是每当我按下另一个按钮以加载另一个页面时,我都必须等待大约3-5秒,而当我等待时,它什么也没有显示,没有div被显示,只有背景。

Is it possible to fix this? 有可能解决这个问题吗? Or maybe, is it possible inserting an LOADING image or text to let the user know that it's loading? 或者,是否可以插入LOADING图片或文本以使用户知道其正在加载? so while the page is being loaded, the user sees : "LOADING.." or some loading icon. 因此,在加载页面时,用户会看到:“ LOADING ..”或某些加载图标。

This should get you going in the right direction. 这应该使您朝正确的方向前进。

Also I don't know what's with all of the different effects you have on $(this) either. 我也不知道您对$(this)所有不同影响是什么。

$(function(){ 
    $(".loading-image").show();

     $('#galleries').hide().load("letters/index.php", function(){
          $(this).slideDown(1);
          $(this).slideUp(1);    
          $(this).hide();
          $(this).slideDown(1500);/* or fadeIn() or any other effect*/

          $("#data").hide(); //replacing your getElementById


          $(".loading-image").hide();

      });

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM