Saturday, February 4, 2017

sjaj

AJAX is an acronym for Asynchronous JavaScript and XML, right? AJAJ is sort of offered up as a replacement term in modern times as the X stands for XML and not JSON and, anymore, we just use JSON. I've never once used XML with AJAX, not to my memory. Maybe XML was shepherded around under the hood in that old web forms Update Panel thing, but never have I actually caught XML at JavaScript and made sense of it. Never. Now will this new name ever be embraced? Never. We are all used to and in love with the term AJAX. It just sounds awesome. It's the name of some Trojan War or Greek Myths hero that we can't quite remember and it's the name of that iconic caustic cleaning product.

Manly! What's not to like about the name AJAX? Anyways, I thought of this because I ran into a way in which the beginning of the acronym should be challenged the way the ending really should be. Behold:

var showStopper = function(url) {
   var whatever=new XMLHttpRequest();
   whatever.open("GET", url, false);
   whatever.send(null);
   return whatever.responseText;
};

 
 

We are not waiting for a promise to come back in the above code. The process will just hang until we get something back. The asynchronous part of the process is replaced with a synchronous one and you could describe this as SJAJ it seems. I didn't know this was even possible. It's not recommended. I saw some sort of warning while I did this about how it was deprecated, and it's not the sort of thing I would normally brush across as I normally never use XMLHttpRequest directly but instead find myself using a framework like jQuery or Angular 2 which has its own, better way of doing AJAJ which I suppose wraps XMLHttpRequest under the hood and doesn't allow for stupid stuff like synchronous calls. The code above just scrapes from a URL, returning whatever may be there, conditionallessly.

No comments:

Post a Comment