Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

jQuery.ajax() method's async option deprecated, what now?

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.

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.

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();
    });
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...