0

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>
Community
  • 1
  • 1
gmustudent
  • 2,229
  • 6
  • 31
  • 43
  • 1
    ['ware the w3schools.](http://w3fools.com/) – Matt Ball Aug 19 '12 at 15:37
  • What *does* happen? Anything in the JS log? Server log? Did you try debugging the JS by console.log-ging or breakpoints? – Dave Newton Aug 19 '12 at 15:44
  • I am not familiar with any of those debugging techniques. Trying to google them now to see how I can use them. Currently when I submit the form the page refreshes and shows empty tabs. And the div below the form does not populate. – gmustudent Aug 19 '12 at 15:49

0 Answers0