Why XML? Why not JSON?
Disclaimer: I was not a developer at that time, so my knowledge might not be very accurate. Correct me if I'm wrong.
This is a fair question, considering today's practices. The name is, as often times, carried on for backwards compatibility I think.
From what I read (en.wikipedia.org/wiki/XMLHttpRequest) XMLHttpRequest's API was at first more of a special purpose solution, which seemed to make sense to have in the browser as well. Considering browser wars, from back in the days, other vendors probably ported the APIs to make "modern" websites work on their browsers as well, not just in Internet Explorer.
XML is a superset or general form of HTML/XHTML (Incorrect, see comments), and was the go to format for plain text data transfers (considering SOAP web services). Due to it's similarities to HTML it was fine to use it in browsers, as the parsing technology was already present. XML only recently (okay, some years ago) mostly got ditched for JSON due to XML's verbosity and weak performance when parsing.
Furthermore JSON was pretty new at the time XHR was introduced. And the initiative to standardize it had just started (https://en.wikipedia.org/wiki/JSON#History). Major players started using the format about 5 five years after XMLHttpRequest was introduced.
So using XML for data transfer totally made sense. The object was dubbed because of that, and nobody wanted to break the web.
We might see a similar development, when Protocol Buffers, or anything similar will be standardized and in wide use.
Marco Alka
Software Engineer, Technical Consultant & Mentor
Because history. There was a time, when there was no JavaScript and HTML was just some kind of XML document (even though they really are different! Both are bases on SGML). That's when Microsoft introduced the <iframe> tag in order to load HTML into HTML. They refined the technology and added a
XMLHTTPcomponent to their client scripting solutions back then, which was able to fetch XML and display it as news feeds on their homepages. In the end, the technology was adapted to JavaScript as means to have a standard way for all browsers to do what IE was already able to. The basic idea was still to just get XML and display it, so it was asynchronious JS (in the background) and XML (the stuff it was invented for). Read the more elaborate story on WikipediaThat's why, even when we use JSON or some other data format today, it is still called AJAX. However, there are a few people (me included), who want to be more specific. When I use JSON as data protocol, then I use
AJAJ. Unfortunately, that term is not standardized and I do not believe that it will ever be. We have WebSockets and WebRTC which are in many situations the more appropriate way to exchange data between one or more client web applications and a server.