jQuery.ajax()方法的async选项去precated,现在该怎么办? [英] jQuery.ajax() method's async option deprecated, what now?

查看:225
本文介绍了jQuery.ajax()方法的async选项去precated,现在该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery 1.8中,使用异步的:在 href="http://api.jquery.com/jQuery.ajax/">的jQuery阿贾克斯()是德precated
但究竟有多少网页你见过一个载入画面,而没有在后台持续AJAX通信?我可能已经看到了其中的数千人。

As of jQuery 1.8, the use of async:false in jQuery.ajax() is deprecated.
But how many webpages have you seen with a "loading screen" while there is an ongoing AJAX communication in the background? I have probably seen thousands of them.

我的情况是,我写的移动应用程序,需要加载一个语言文件。而且一开始我加载语言文件,我检索按钮和其他GUI元素从语言文件中的文本。

My case is that I am writing a mobile app that needs to load a language file. And at the beginning I load the language file and I retrieve the text of the buttons and other GUI elements from the language file.

这对我来说是非常糟糕的。因为如果语言文件丢失,则GUI不应出现。那么,如何解决这个问题呢?把我所有的code。在成功回调?这doesn't看起来像一个良好的编码习惯我。我可以解决这个问题的另一种方式?

This is really bad for me. Because if the language file is missing, the GUI shouldn't appear. So how do I solve it? Put all my code in the success callback? That doesn´t seem like a good coding practice to me. Can I solve it another way?

推荐答案

解决的办法是手动添加一个覆盖到prevent与界面交互的用户,然后将其删除,一旦AJAX查询完成。

The solution is to manually add an overlay to prevent the user to interact with the interface, and then remove it once the AJAX query is done.

$(function() {
    show_overlay();        

    $.ajax({
        // Query to server
    }).done(function() {
        // Verify good data
        // Do stuff
        remove_overlay();
    });
});

这篇关于jQuery.ajax()方法的async选项去precated,现在该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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