What is the essence of AJAX? For example, I want to have a link on my page such that when a user clicks this link, some information is sent to my server without the reloadin
The essence of AJAX is this:
Your pages can browse the web and update their own content while the user is doing other things.
That is, your javascript can send asynchronous GET and POST requests (usually via an XMLHttpRequest object) then use the results of those requests to modify its page (via Document Object Model manipulation).
Ajax is more than reload just a part of the page. Ajax stands for Asynchronous Javascript And Xml.
The only part of Ajax that you need is the XMLHttpRequest object from javascript. You have to use it to load and reload small part of your html as a div or any other tags.
Read that example and you will be pro sooner as you think!
<html>
<body>
<script type="text/javascript">
function ajaxFunction()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
alert("Your browser does not support XMLHTTP!");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.myForm.time.value=xmlhttp.responseText;
}
}
xmlhttp.open("GET","time.asp",true);
xmlhttp.send(null);
}
</script>
<form name="myForm">
Name: <input type="text" name="username" onkeyup="ajaxFunction();" />
Time: <input type="text" name="time" />
</form>
</body>
</html>