简体   繁体   English

jQuery的/ JavaScript的:如何顺序(而不是并行)加载(一些)图像?

[英]jquery/javascript: how to load (some) images sequentially rather than in parallel?

The problem is unique to Single Sign On sites with cross site links. 该问题是具有跨站点链接的单一登录站点所独有的。 The portal (my project) maintains a database of metadata describing images on two remote sites. 门户(我的项目)维护着一个描述两个远程站点上图像的元数据数据库。 All 3 require Shibboleth authentication and use the same identity provider. 所有3个都需要Shibboleth身份验证并使用相同的身份提供者。

When users connect to machine that does not have an existing session they are redirected to the Identity Provider, if they have a session there info a back channel is used to create a local session. 当用户连接到没有现有会话的计算机时,他们将被重定向到身份提供者,如果他们有会话,则使用后向通道创建本地会话的信息。

The problem occurs when a browser opens multiple simultaneous connections that need to create a new local session. 当浏览器打开多个同时需要创建新的本地会话的连接时,就会发生此问题。 One connection might succeed but most if not all will fail. 一个连接可能会成功,但大多数(如果不是全部)都将失败。

The solution (I think) is to have a small image from each remote site on the first portal page that are loaded one at a time. 解决方案(我认为)是在第一个门户网站页面上的每个远程站点上都有一个小的图像,每次加载一个。 Once the sessions are established everything works well. 建立会话后,一切都会正常进行。

Finally my question: how do I load a list of remote images one at a time waiting for each to fully load before requesting the next one. 最后,我的问题是:如何在请求下一个远程映像之前一次加载一个完整的远程映像列表。

var imageNames = ['img1.png', 'img2.png'];
var counter=0;

function loadImage(imageName, counter){
  $.get(imageName).done(
    function(){
      console.log(imageNames[counter] + ' loaded');
      counter++;
      if(counter < imageNames.length){
        loadImage(imageNames[counter], counter);
      }
    }
  );
}

loadImage(imageNames[counter], counter);

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

相关问题 有没有办法(JavaScript或jQuery)顺序加载图像(防止并行下载) - Is there a way (JavaScript or jQuery) to sequentially load images (prevent parallel downloads) 如何使用JavaScript加载页面而不是重定向? - How to load pages with JavaScript rather than redirect? 如何使手风琴菜单顺序关闭而不是同时打开? - How to make accordion menu close and open sequentially rather than simultaneously? 如何确保图像顺序加载 - how to make sure images load sequentially 优化反应代码以同时加载来自多个源的数据而不是顺序加载 - Optimise react code to load data from multiple sources simultaneously rather than sequentially 如何从文件夹动态加载图像而不是在数组中输入每个图像名称? - How to load images dynamically from a folder rather than entering each image name in an array? 动态顺序加载javascript - load javascript dynamically and sequentially 使用顺序承诺在Javascript和jQuery中运行一些Ajax请求 - Use sequentially promise to run some ajax requests in Javascript and jQuery 如何创建一个使用4个图像来导航而不是文本的JQuery内容滑块? - How do I create a JQuery content slider that uses 4 images to navigate rather than text? 如何从AJAX调用[Web开发]顺序加载图像? - How to sequentially load images from an AJAX call [Web Development]?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM