加载GIF"冻结"当code正在执行 [英] Loading gif "freezes" when code is executing

查看:125
本文介绍了加载GIF"冻结"当code正在执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我追加动画GIF这是一个加载条。该GIF前面的code定义,然后,我只是做如下..

I'm appending an animated gif which is a loading bar. The gif is defined earlier in the code and I then just do the following..

document.getElementById("loading").style.display = "inline";
//some if statements.
do_ajax(params);

Ajax调用看起来像......

The ajax call looks something like...

    var uri = getURL(params);
    var xhr = new XMLHttpRequest();
    xhr.open("POST",uri,false);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
    xhr.send(null);

显示加载GIF。然后我进行一些检查(if语句),其次是一个AJAX请求。然而,GIF,而这一切的code正在执行冻结,仅开始搬家,一旦code已经执行完毕。为什么是这样?如何解决这个问题?

to show the loading gif. I then perform some checks (if statements) followed by an AJAX request. However, the gif freezes while all this code is executing and only begins to 'move' once the code has finished executing. Why is this? How do I fix this issue?

我使用的是Chrome浏览器11

I'm using Chrome 11

推荐答案

您使用同步XHR。这将锁定浏览器,同时等待完成该请求。很显然,它会导致一个严重的用户界面问题。

You are using synchronous XHR. This will lock the browser whilst waiting for the request to finish. Obviously, it causes a serious UI issue.

尝试同步。设置的open()的第三个参数。您还需要分配 readystatechange 事件监听成功。

Try asynchronous. Set open()'s 3rd parameter to true. You also need to assign the readystatechange event and listen for success.

进一步阅读

这篇关于加载GIF"冻结"当code正在执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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