الاثنين، 12 فبراير 2018

What is AJAX?

What is AJAX?
AJAX is a technology used to facilitate real-time data
changes and updates on a page without requiring a page
reload.
AJAX stands for Asynchronous Javascript And XML
.
Let's break that down:
Asynchronous: The response from the server doesn't
have to be immediate, like a page load does. Other stuff
can happen in-between.
Javascript: The client-side language which you use to
make requests to and handle responses from the server
XML: The format often used to pass data between
Javascript and the server

No, really, what is AJAX?
AJAX is basically a general term for making your webpage
able to do dynamic stuff on the server (like make a new
post, remove a user, etc) without having the user click on a
link which loads a new page.
It works similar to how any fancy JavaScript effect works,
except that the JavaScript makes a call to some page on
the server in the middle which causes something "real" to
happen.
Remember, JavaScript is client-side. It can't affect the
database directly. It needs to use a technique like AJAX
to cause an actual effect on the server. 
 
A simple example
mypage.html
<h1>Stuff</h1>
<div id="box">
</div>
<a href='javascript:getStuff();'>Get stuff via AJAX.</a>
<script type='text/javascript'>
function getStuff() {
// Pseudocode for simplicity
request = makeHttpRequest("get_stuff.php");
document.box.innerHTML = request.text;
}
</script>
get_stuff.php
<?php
echo "This is the stuff that will go in
the box.";
?>
What happens?