定期测试页面加载后添加到DOM中的元素 [英] Periodically testing of elements that are added to the DOM after pageload

查看:77
本文介绍了定期测试页面加载后添加到DOM中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面供您上传视频,然后对这些视频进行编码(很像Youtube).编码部分可能需要一些时间,如果要通过定期从页面内部轮询编码状态来完成编码,我想自动向用户显示,如果编码完成,我想用播放"按钮替换编码图标,以便用户可以播放视频.

I've got a page where you upload videos, those videos are then encoded (much like Youtube). The encoding part can take some time and I want to automatically show the user if encoding is done by periodically polling the encoding status from within the page, if encoding is completed I want to replace the encoding icon with a "play" button so the user can play the video.

因为上传的视频列表本身是使用AJAX(使用jQuery)放入DOM的,所以我很难确定如何做到这一点.我想为此使用jQuery,但不知道jQuery是否可以做到这一点.

Because the list of uploaded videos itself is put into the DOM using AJAX (with jQuery) I have trouble wrapping my head around how to do this. I'd like to use jQuery for this, but I don't know if jQuery can do this.

因此,步骤如下

  1. 用户上传视频
  2. 用户返回到页面
  3. 用户折叠打开"已上传视频的列表,一些编码尚未编码,编码的具有播放按钮,未编码的具有沙漏图标
  4. 用户等待,直到尚未编码的视频的图标变成播放按钮
  5. 用户按下播放按钮,然后播放电影

我的问题仅在步骤4上.服务器端部分也已完成.

My problem is only at step 4. The serverside part is all done as well.

推荐答案

如果问题是您不知道如何每隔X秒轮询一次页面,则可以使用setTimeout(function ,毫秒)和setInterval(function,毫秒).您将轮询代码放入函数的定义中.

If the issue is that you don't know how to get the page to poll the server every X seconds, you can do this with javascript using setTimeout(function, milliseconds) and setInterval(function, milliseconds). You put your polling code in the definition for function.

这是文章,其中包含详细信息.

Here's an article with details.

这篇关于定期测试页面加载后添加到DOM中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆