How does jQuery AJAX synchronous query work?

Does the jQuery.ajax({async: false})object use XMLHttpRequest?

If so, how is the request synchronous?

Is there any mechanism inside the function definition that allows you to wrap an asynchronous request sent by XHR in a synchronous shell?

I ask because I want to wrap asynchronous function calls in a synchronous wrapper.

EDIT

I want to do this for dependencies. I do not need to run anything until all external dependency scripts load, however I would prefer not to load each file synchronously.

Basically, I want this:

require(['lib1.js','lib2.js'])

Library1Function();
Library2Function();

Load lib1 and lib2 at the same time, but block until both are loaded.

, , , , , , .

EDITx2

, :

# lib2.js
window.Library2Function = function(input) {
  alert(input);
}

# lib1.js
require('lib2.js', function() {
  window.Library1Function = function() {
    window.Library2Function('Hi there');
  }
});

# main.js
require('lib1.js', function() {
  window.Library1Function();
});

, main.js lib1.js. , Library2Function lib2.js, lib1.js.

+3
1

jQuery.ajax({async: false}) XMLHttpRequest?

.

XMLHttpRequest.prototype.open async . ( ), . .

, .

? , , , "".

+1

Source: https://habr.com/ru/post/1759632/


All Articles