I think google.com uses AJAX, but when I looked at the source of google.com, I didn’t find "XMLHttpRequest".
Also I think phpMyAdmin uses AJAX, but when I looked at the source of phpMyAdmin, I didn’t find "XMLHttpRequest".
So how are google.com and phpMyAdmin using AJAX without using XMLHttpRequest
? could they be using a library and this library uses XMLHttpRequest
?
2
Answers
Ajax is a general term meaning "Make an HTTP request from JavaScript without leaving the page". There are numerous ways to do that and some of them are more debatable than others.
<script>
element into the page which calls a callback when it loads. It’s a hack to get around the Same Origin Policy that has some security risks and has been superceeded by CORS.There are numerous libraries which wrap themselves around those various APIs.
To answer your question about whether google.com uses XMLHttpRequest, the answer is yes.
Using Chrome, open the dev tools and go to the network tab. Then, in the search box of the webpage, type a letter as if you were going to do a web search. Google then sends an Ajax XMLHttpRequest to a server to get autocomplete suggestions based on the letter you typed.
I typed the letter "a", which resulted in several requests, one of which was to a url beginning with "search?q=a". This can be seen in the "Name" column in the network tab. To the right is a column "Type", which shows the request is an XHR request (meaning it was made via an XMLHttpRequest – fetch requests will have "fetch" as the value here). Further right is the column "Initiator", which references the Javascript that initiated that network request.