When it comes to Ajax, callbacks are used due to its asynchronous nature.
I desire my request to the remote URL to wait until a response is received, akin to how Ajax operates, but without the asynchrony. In other words, I seek to create a JAX call.
Is there a method to achieve this (utilizing JQuery) (... offering a solution using JQuery or another approach):
function get_data() {
$.ajax({
type : "POST",
url : "/foo"
}).done(function(data, textStatus, jqXHR) {
return data;
}).fail(function(jqXHR, textStatus) {
return null;
});
}
var data = get_data();
// process `data`
This question stems from a place of curiosity and eagerness to expand knowledge.
Sometimes, waiting for a reply before proceeding makes sense. I don't mean to halt the browser, just the script's runtime.