jQuery的加载,而异步虚假的图像 [英] jquery loading an image while async false

查看:115
本文介绍了jQuery的加载,而异步虚假的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给用户知道有事情发生,而我所做的与jQuery的AJAX调用一个旋转的GIF图像。我必须使用异步:假的,因为否则code会很困惑,我们结束了一个糟糕的会话变量。这是我(即不显示GIF后才呼叫已冻结在屏幕上。)

I want to give a spinning gif image for the user to know something is happening while I am doing an ajax call with jquery. I have to use async:false because otherwise the code gets confused and we end up with a bad session variable. Here is what I have (that does not show the gif until after the call has frozen the screen.)

$('#status' + itemNum).html("<img width='14px' src='/style/images/spinner.gif'>");
if (foo == "bar") {
$.ajax({
   type:"POST",
   url: "foobar.html",
   async:false,
   data: "val1=" + escape(newValue) + "&val2=" + fieldName + "&val3=" + newValue2
   })
} else {
$.ajax({
   type:"POST",
   url: "foobar.html",
   data: "val1=" + escape(newValue) + "&val2=" + fieldName + "&val3=" + newValue3
   })
   document.getElementById('status' + itemNum).innerHTML = "SAVED";
}
$("#status" + itemNum).show();
setTimeout("fade_out('"+itemNum+"')", 1000);
}

在这种情况下,我只希望当异步富=酒吧。任何人都可以让我知道为什么spinner.gif加载后调用。我想,可能是因为微调不是其他地方并没有在加载它的延迟,但它仍然在多次调用(应该是在高速缓存中的话)并没有显示出来,所以我难倒。

In this case I only want the async when foo = bar. Can anyone let me know why the spinner.gif loads after the call. I am thinking that might be because the spinner isn't anywhere else and there is a delay in loading it, but still it doesn't show up when called multiple times (should be in cache by then), so I'm stumped.

谢谢!

推荐答案

这是不可能的。
由于Javascript运行在UI线程,异步:假将冻结browserm包括所有的动画

This is not possible.
Since Javascript runs in the UI thread, async: false will freeze the browserm including all animation.

您需要修复您的code来处理异步请求。

You need to fix your code to handle asynchronous requests.

这篇关于jQuery的加载,而异步虚假的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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