What is AJAX?
Topics

nothing works without HTML -->



<div>


<br/>
<img src="../images_July_2015/1280px-The_Suicide_of_Ajax.svg.png" width="799" height="602" alt="webtechnology, ajax, Asynchronous JavaScript and XML" />

<h6>There's a button below (sneak peek) to peek at the code.</h6>



<h1 itemprop="headline">Using technologies like AJAX (Javascript + Javascript) - guarana for your site</h1>




<p>
Ajax is a marketing gag because in essence it is Javascript neatly wrapped up as "Asynchronous JavaScript and XML" and it doesn't
pertain to the Trojan hero Ajax. At least that's what I thought when I first heard that name.
</p>


<p>
First we need a JavaScript context (that is, we create an object, required to get data). Press the "peek" button below, to see the script.
</p>



<script>
var context=null;
context = new XMLHttpRequest();
</script>







<p>Then we shall open the file from the server asynchronously. This means that the file is loaded in the background
and the user won't have to be kept waiting if it is a very huge file. Now this is very interesting. You as a user
have already loaded this page into your browser, and then there goes Ajax loading another file via javascript.</p>


<div id="display"></div><!--This div is still empty. After the script has been executed the "innerHTML" is filled by Ajax-->




<script>




if (context !=0)
{
context.open("GET", "examples/easy.txt", true);//GET not POST,name of the file, true for asynchronous loading
context.onreadystatechange = show_me;//if something has changed call "show_me" checking if state "4" has been reached (meaning success)
context.send(null);//no parameters handed over to "examples/easy.txt"
}

function show_me() {
if(context.readyState==4) //"4" means that the request has been completed
{
document.getElementById("display").innerHTML = context.responseText;//put something into the div with the id "display"
}
}



</script>

<p>You can call the file <a href="examples/easy.txt">"examples/easy.txt"</a> to check.</p>


<br>
<br>
<br>
<?php $Weblog->share ();?>


<br>
<br>
<br>



</div>

Sneak peek of the server side code