I know more or less what AJAX is. However, it is still not clear to me how to use it, and I would like to learn how to use it because I see that it is something elementary today.
I have searched for tutorials on the internet, but they are mostly outdated and old. My question is: Could you give me some simple code example you have and how to learn how to use it? Do I need a server side language like PHP?
Briefly
AJAX is a technique for making a request to a web resource. For example, reading a web page.
The main thing about AJAX is that it is done asynchronously . And it is asynchronous in terms of global page loading, since it allows you to make a request once the page has already been fetched, without needing to reload it.
when to use it
Reading your question, it seems to me that you don't even know what to use it for yet... Well, first I think you should think about what data you want to get from the web when the page is already loaded. And this would be, for example, when the user clicks on an element, looking for more information elsewhere, or similar.
Code Example
Call example:
No. You need to define what you want to do. It can be getting a page generated with PHP, it can be regular HTML, it can be a WebService, it can be any web resource you can think of.
More info: MDN > AJAX > Getting Started
I have a somewhat basic AJAX example. You must use PHP on the server side and jQuery on the client (bootstrap for layout).
Insert the code in your PHP server and name it as "ajaxSleep.php", it will return the variables that you send by AJAX from the client.
This is the code that implements jQuery's AJAX, name it whatever you see fit, and save it next to "ajaxSleep.php":
Remember to add the bootstrap 3 .css and the bootstrap 3 and jQuery 3 .js
Paste everything into a PHP 5.6 or higher server. The parameters travel from the form to the server via AJAX, and PHP takes care of returning the same values.
To keep us a little up to date, since ES6 came into our lives (although it seems that many of you resist) we have available the fetch API to make it easier for us to make AJAX calls.
Example
Here are some interesting links:
In JQuery you have good material to use ajax: https://learn.jquery.com/ajax/jquery-ajax-methods/
JQuery is a great library of javascript functions for those of us who are lazy and in a hurry.
With Jquery, I send you an example that I use very frequently for the use of ajax, I use it to extract data in Json format.
I hope to be helpful.