Introduction
AJAX is a mechenisme for communicating with server through background. It enables your client web site to load and sending data from and to server respectively without reloading the page.Sending Data To Server
Here's a simple example on how to use ajax.
Program Code: Client Side
<input type="text" id="name"/>
<input type="button" value="Send" onclick="sending()"/>
<script>
function sending(){
var name = document.getElementById('name').value;
var ajax = new XMLHttpRequest();
ajax.open("GET", "hello.php?name="+name, false);
ajax.send();
}
</script>
<input type="button" value="Send" onclick="sending()"/>
<script>
function sending(){
var name = document.getElementById('name').value;
var ajax = new XMLHttpRequest();
ajax.open("GET", "hello.php?name="+name, false);
ajax.send();
}
</script>
And on the server side, you need to write the code to handle it. Here's a code on PHP.
Program Code: hello.php
$name = $_GET['name'];