AJAX stands for A
ML. it is a technology that enables a webpage to communicate with a file on its server without the webpage reloading or the web user noticing.
A server is a computer or device where your website lives. If your webpage or website is on your personal computer, then your PC is the server. If it is on your phone, that is also the server. All websites are hosted on a server or computer.
with few but powerful properties
that can be used in communicating with a website's server. The AJAX Object
is supported on all modern browsers.
What You Can Do With AJAX
- Send a request to a file on a webpage server without the webpage reloading.
- Get the content of such files or documents.
- Use the content to update your webpage dynamically without the webpage reloading.
- Send request to files to run server side codes without the webpage reloading. For example, assuming PHP is installed on your server, you can therefore send requests to PHP files and have them run queries to perform whatever operations on your server and database.
Just as the full meaning of the name "AJAX" may suggest, the technology was originally designed to help get contents of XML (eXtensive Markup Language) documents but today, AJAX can practically be used in sending request to whatever kind of document e.g XML, TEXT, PHP, HTML, CSS, JS files and etcetera.
AJAX In Practice Example
Here are some cases of how websites are using AJAX to build not just interactive but dynamic webpages.
- Have you ever tried doing a Google search and then, as you type in your search query, Google returns suggestions stored in its servers? That's AJAX.
- Have you ever visited Facebook on a modern browser and you find out you can do a lot of things involving database operations without the Facebook page reloading e.g liking/disliking a post? That's what AJAX can help you achieve.
- Let's come home to stackbeginner.com. Have you ever tried searching for contents here and then, as you type in your query, pages related to your query are being returned from our database? That is AJAX.
- Our "TEST YOURSELF" QUIZ and commenting systems have AJAX as their backbone.
HOW AJAX WORKS
Below is how AJAX requests are usually implemented on a webpage.
- An event happens on a webpage. For example, a user clicks on a button to submit some requested information.
- A function is called to handle that event.
- Inside the function, an AJAX or HTTP request Object is created.
- Methods and properties of the Object are implemented to send the request to a particular file or document on a server.
- Request sent. Server returns responses (Good or bad responses).
- if response is good. That is, successful, we get whatever text or data (if any) returned by the server from that document.
- We display the data or text if need be.
In this chapter, you will learn all properties and methods that will enable you send HTTP or AJAX requests.
- AJAX can simply be seen as sending requests to files contained on a web page's server without the webpage reloading or a user noticing.
- We send such requests to either get whatever is the content of such files or documents or to execute server codes contained in such files.
- As an Object, there exist properties and methods that help us fully achieve our aim.
- You can only send requests to files on your server. You can't send to other websites' servers for security reasons.
- You will learn all you need to start sending AJAX requests to your server in this chapter.