简体   繁体   English

浏览器ajax异步调用页面继续加载

[英]browser ajax asynchronous call page keeps loading

I've made a website with photos on it that get refreshed every second. 我已经制作了一个网站上有照片,每秒都会刷新一次。 I fetch these photos from a web server with a jQuery $.ajax() call every second. 我每秒都通过jQuery $ .ajax()调用从Web服务器获取这些照片。 This creates some sort of infinite photo-loading loop, which I want. 这创造了我想要的某种无限的照片加载循环。

However, my page just keeps on loading (the spinning icon keeps spinning or loading bar is loading forever). 但是,我的页面只是继续加载(旋转图标保持旋转或加载栏永远加载)。 Especially on Chrome this is annoying, because there's a spinner next to my mouse. 特别是在Chrome上,这很烦人,因为我的鼠标旁边有一个微调器。

How can I prevent that it doesn't look like my page is loading forever, without changing functionality? 如何在不更改功能的情况下防止它看起来像我的页面永远不会加载? Thanks.. 谢谢..

I would defer the parsing of your javascript until the end of the page load. 我会推迟解析你的javascript直到页面加载结束。 Use Googles .js file found here: http://code.google.com/p/domready/ 使用在此处找到的Googles .js文件: http//code.google.com/p/domready/

This way your page will load faster, complete loading, and then start doing your ajax calls. 这样,您的页面将加载更快,完全加载,然后开始执行您的ajax调用。

You shouldn't be hitting your server every second like that. 你不应该像这样每秒都打你的服务器。 Because while it may work for a single person, once you go live and more people visit your site, it may kill your server. 因为虽然它可能适用于单个人,但一旦您上线并且更多人访问您的网站,它可能会扼杀您的服务器。

Warning aside, you might try waiting till the page is fully loaded before firing off your ajax. 除了警告之外,您可能会尝试等待页面完全加载,然后再关闭您的ajax。 You could use setTimeout to wait a few seconds. 您可以使用setTimeout等待几秒钟。 However, here I think you may be getting the loading notification because the images are being fetched from the server. 但是,在这里我认为您可能正在获取加载通知,因为图像是从服务器获取的。

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

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