Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 878
Juw Avatar asked Jul 12 '12 08:07

Juw


People also ask

Is Ajax async false deprecated?

As of jQuery 1.8, the use of async:false in jQuery. ajax() is deprecated.

Is AJAX successful deprecated?

ajax function is deprecated.

Why is synchronous AJAX deprecated?

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. So I was simply wondering where and why synchronous AJAX requests are used within pace.

Is jQuery AJAX asynchronous?

The jQuery Ajax async is handling Asynchronous HTTP requests in the element. It is a procedure to send a request to the server without interruption. It is an Asynchronous method to send HTTP requests without waiting response. It is a function to working on a server without associating more than on request.


1 Answers

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();     }); }); 
like image 81
Jørgen R Avatar answered Sep 18 '22 12:09

Jørgen R