Hello
I have written a sample application using JSF1.2 Core(without using richfaces/myfaces) which is using AJAX inside a Portal Environment(JSR 286,WebSphere Portal 6.1).
I have written
java script inside my jsp/.xhtml file which will ajaxify and invoke my
servlet and give the response.while constructing the url ,it is getting problematic.I am not getting the status of xmlHttpRequest,able to get the xmlHttpRequest.readyState.Please give me comments/suggestions on this.
this is my .xhtml/jsp
<script type='text/javascript'>
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}
var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object
function ajaxFunction() {
var getdate = new Date(); //Used to prevent caching during ajax call
if(xmlhttp) {
xmlhttp.open("GET","gettime?"+ getdate.getTime(),true); //gettime will be the servlet name
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(null);
}
}
function handleServerResponse() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
alert("######## ready state val#########" +xmlhttp.status);
document.myForm.time.value.innerHTML=xmlhttp.responseText; //Update the HTML Form element
}
else {
alert("Error during AJAX call. Please try again"+xmlhttp.responseText);
}
}
}
</script>
<body>
<div class="home-container">
<h:form id="myForm">
<f:view>
Server time
<h:inputText id="time"/>
<h:commandLink value="click this button..." onclick="ajaxFunction()"/>
<div id="msg">
xmlhttp.open("GET","gettime?"+ getdate.getTime(),true); // think this line getting problematic
gettime is my servlet class name.I have configured this in web.xml properly