Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What *exactly* is AJAX? [closed]

Tags:

ajax

I know what AJAX stands for. I know javascript passably well. But frankly I'm just not clear on what AJAX is.

Because all I know about it is XMLHttpRequest(), but it must be so much more than that. Can someone give a clearer explanation of how AJAX isn't just a certain aspect of perfectly ordinary JavaScript? I can't see how it's anything different.

EDIT: I also understand that it allows you to update a page without reloading. That's fantastic, I know. But I still don't see how that's anything more than standard JavaScript.

like image 615
temporary_user_name Avatar asked Apr 08 '12 00:04

temporary_user_name


2 Answers

Well it's not as if it's magic or something. It really is ordinary Javascript, and it's ordinary XML (or JSON, or some other data format). And it runs in a browser. None of this is particularly new or novel. Microsoft was talking about "DHTML" in 1996, and officially released it in 1997.

But combining these existing things, is an approach that is common enough and useful enough to have earned a specific name. AJAX refers to the pattern of using asynchronous requests, driven in Javascript logic running in the browser, to retrieve data in XML format or otherwise. Typically the retrieved data is then used to update the HTML page in some way, without causing a full page refresh.

You said you don't see how that's anything more than standard JavaScript. Using Javascript in a browser you could do something as simple as run a timer that pops up an alert after it expires. Or you could perform a fadeout on a background color. Or do jQuery effects like accordion popouts. Or dynamically sort an HTML table by different columns. Even autocomplete in textboxes is possible using Javascript. These all cause the UI to be updated, but they don't necessarily retrieve any data. (in some cases autocomplete will do so, but not generally).

AJAX always involves communication and data retrieval, so it is distinct from "standard Javascript".

like image 117
Cheeso Avatar answered Nov 15 '22 06:11

Cheeso


I think to gain an understanding you have to look into where the XMLHttpRequest came from. It was not a standard part of JavaScript at the time. You could not make asynchronous HTTP requests from the browser with pure JavaScript. The XMLHttpRequest object was first introduced by Microsoft in IE5 as an ActiveX control. So with that in mind, the way we use JavaScript today has evolved from a much simpler scenario.

I suggest you read the Wikipedia page - particularly the history section. There's nothing overtly fabulous about Ajax, it was just a coined term for what was at the time a new way of doing things, and it's stuck.

http://en.wikipedia.org/wiki/AJAX

In particular read the definitive article http://www.adaptivepath.com/ideas/ajax-new-approach-web-applications - this is probably the best way to understand where Ajax came from and indeed what it actually means. Probably most importantly

Defining Ajax

Ajax isn’t a technology. It’s really several technologies, each flourishing in its own right, coming together in powerful new ways. Ajax incorporates:

  • standards-based presentation using XHTML and CSS;
  • dynamic display and interaction using the Document Object Model;
  • data interchange and manipulation using XML and XSLT;
  • asynchronous data retrieval using XMLHttpRequest;
  • and JavaScript binding everything together.

As noted, the exact definition of Ajax is quite hard to pinpoint these days. The methodologies are prone to updating themselves as the browser evolves, but these were the underlying principles at its conception.

like image 27
Matt Esch Avatar answered Nov 15 '22 07:11

Matt Esch