Ajax without callback

Is there a function in the javascript framework that:

  • makes an AJAX request
  • returns an answer

    (it does not take a callback function as an argument)

I basically want to execute an AJAX request in the same way as SQL queries in C, python or something else.

+4
source share
3 answers

This will be a synchronous query, and jQuery has this function: http://api.jquery.com/jQuery.ajax/ I don’t know if this is really synchronous, as I have never tried. Look at the async parameter in this documentation, set it to false.

+2
source

Yes you can, but this is a very bad practice. The javascript engine is single-threaded, and you run the risk of blocking the user interface.

+5
source

No, because if it does not make a callback, then it is not asynchronous, and subsequently it is no longer AJAX (asynchronous Javascript and XML). Although it is customary to replace X with JSON or text, the Asynchronous part is very important.

You can make a synchronous request, but it has its problems ... especially that sometimes the web page and interface look frozen until the request returns.

+3
source

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


All Articles