Possible Duplicate:
How to use Servlets and Ajax?
Earlier this morning I created a Java Web Application to take in Employee Data through an HTML form and give back Information. I had the information display on the same page as the form in a show hide div. Worked great!
So then I thought this would be a good place to practice/learn some ajax! So that instead of showing and hiding the div with the jsp tag below the form, I would instead put the jsp tag in another page, and populate the div when necessary. Well that was the plan anyway!
So this is my first attempt ever using ajax so I have been following the w3schools Ajax Tutorial but unfortunately my program is not working. The information needed from result.jsp is not being grabed. Any guidance on how I can get the content and display it in the div correctly would be greatly appreciated. Thank you for reading! And to clarify, this worked great as a show hide div before I added the ajax in.
Ajax (Following w3schools template)
function writeInformation()
{
var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
else
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
document.getElementById("empInformation").innerHTML = xmlhttp.responseText;
}
xmlhttp.open("get", "result.jsp", true);
xmlhttp.send();
}
result.jsp (The content I want displayed in the div. Currently none of this code displays.)
<h2>Employee Information Below:</h2>
${empAttribute.getResult()}
<p />
<input type="button" onClick="closeEmpInfo()" value="Clear Information" />
The div (Located in index.jsp which is in the same root folder as result.jsp)
<div id="empInformation">
</div>