一个函数使用 jquery.ajax()
方法从服务器获取数据,并把它作为返回值。
如果我使用的异步=真正的函数将返回prematurely空值。
如果我使用的异步=假的等待的功能实在是太漫长。我试着拨动格显示旋转时钟的请求之前正确,但股利不会出现,直到请求结束。
A function uses the jquery.ajax()
method to get data from server and use it as return value.
If I use async=true the function returns prematurely empty value.
If I use async=false the wait for the function is too long. I tried toggle div showing spinning clock right before the request, but the div does not appear until the request is over.
在如何不锁定浏览器或显示等待图标/符号/文本有什么建议?
Any advice on how not to lock the browser or show wait icon/symbol/text?
您不能。同步请求将锁住浏览器,包括你可能会认为可能是未决的动画或DOM修改 - 这就是为什么他们望而却步。有机会,你想从函数返回发射了Ajax请求,这是行不通的异步请求的值 - 修改您的逻辑来处理响应处理的成功回调,一切都会好...
You can't. Synchronous requests will lock up the browser, including any animations you might have going or dom modifications that might be pending - that's why they're discouraged. Chances are, you're trying to return a value from the function firing off the ajax request, which WILL NOT WORK for async requests - modify your logic to handle the response processing in the success callback, and all will be well...