I am using Appfuse 1.94 with struts:
My sample code for Ajax call check below:
"getEventsbyapsid" is method in my action class which returns a string,
form "eagdForm.jsp"
I believe, am making mistake in url variable values,
url="eagdForm.do?methodName=getEventsbyapsid&selectedOption="+selectedOp
tion;
when I check req.responseText, its giving page not found information
(The whole html content, which displays page not found)
Your advice highly appreciated,
<script type="text/javascript">
var req;
/*
* Get the second options by calling a Struts action
*/
function retrieveEvents(){
firstBox = document.getElementById('eagdApsUid');
//Nothing selected
if(firstBox.selectedIndex==0){
return;
}
selectedOption = firstBox.options[firstBox.selectedIndex].value;
//get the (form based) params to push up as part of the get request
url="eagd.do?methodName=getEventsbyapsid&selectedOption="+selectedOption
;
//Do the Ajax call
if (window.XMLHttpRequest){ // Non-IE browsers
req = new XMLHttpRequest();
//A call-back function is define so the browser knows which
function to call after the server gives a reponse back
req.onreadystatechange = populateEvents;
try {
req.open("GET", url, true); //was get
alert("in");
} catch (e) {
alert("Cannot connect to server");
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = populateEvents;
req.open("GET", url, true);
req.send();
}
}
}
function populateEvents()
{
if (req.readyState == 4)
{ // Complete
alert(req.responseText);
document.getElementById("txt1").value= req.responseText;
if (req.status == 200)
{ // OK response
textToSplit = req.responseText
if(textToSplit == '803')
{
alert("No select option
available on the server")
}
}
}
else
{
//alert("Bad response by the server");
}
}
</script>