I am new to Ajax and struggling to get a simple example to work...
Here is the javascript code:
var xmlRequest;
function refreshContent()
{
if (window.XMLHttpRequest)
{
xmlRequest = new XMLHttpRequest();
}
else
{
xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlRequest.onreadystatechange = function()
{
if (xmlRequest.readyState == 4)
{
document.getElementById("tester").innerHTML = xmlRequest.responseText;
}
};
xmlRequest.open("GET", "sample.xhtml", true);
xmlRequest.send();
}
Now, take a look at the sample xhtml page:
<div id="test">
SAMPLE CONTENT
</div>
<button type="button" onclick="refreshContent()">Change Text</button>
The JavaScript file has been called.
I have been testing it and it seems like the "xmlRequest.onreadystatechange" is always null and doesn't trigger the function.
Could there be an issue elsewhere, perhaps on the Tomcat server?