- This topic has 1 reply, 1 voice, and was last updated 15 years, 4 months ago by bipien@yahoo.com.
-
AuthorPosts
-
bipien@yahoo.comMember// ajax.js
// newFunction
function newXMLHttpRequest()
{
var xmlreq = false;
// Create XMLHttpRequest object in non-Microsoft browsers
if (window.XMLHttpRequest)
{
xmlreq = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{//else if S
try
{
// Try to create XMLHttpRequest in later versions
// of Internet Explorer
xmlreq = new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e1)
{//catch S
// Failed to create required ActiveXObject
try
{
// Try version supported by older versions
// of Internet Explorer
xmlreq = new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch (e2)
{
// Unable to create an XMLHttpRequest by any means
xmlreq = false;
}
}//catch E
}//else if E
return xmlreq;
}
/*
* Returns a function that waits for the specified XMLHttpRequest
* to complete, then passes it XML response to the given handler function.
* req – The XMLHttpRequest whose state is changing
* responseXmlHandler – Function to pass the XML response to
*/
function getReadyStateHandler(req, responseXmlHandler) {
return function () // Return an anonymous function that listens to the XMLHttpRequest instance
{
if (req.readyState == 4)
{
if (req.status == 200)
{
responseXmlHandler(req.responseXML);
} else
{
alert(“HTTP error “+req.status+”: “+req.statusText);
}
}
}
}
// train definition.js
function getTrainSubType(frm, value)
{
var httpRequest = newXMLHttpRequest();
httpRequest.onreadystatechange = getReadyStateHandler(httpRequest, updateSubTypeList);
httpRequest.open(“POST”,”ajax.do?subAction=getTrainSubTypes”, true);
httpRequest.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded; charset=UTF-8”);
httpRequest.send(“traintype=”+value);
}
function updateSubTypeList(xmlMessage)
{
try
{
var subType = document.getElementById(‘trainSubType’);
initializeSelect(subType,false);
xmlMessage=xmlMessage.getElementsByTagName(“XML-MESSAGE”)[0];
var status = xmlMessage.getElementsByTagName(“STATUS”)[0].firstChild.data;
if(status==’SUCCESS’)
{
var subTypeList = xmlMessage.getElementsByTagName(“SUB-TYPE-LIST”)[0].getElementsByTagName(“SUB-TYPE”);
for(var i=0;i<subTypeList.length;i++)
{
subType.options[i+1]=new Option(subTypeList[i].getElementsByTagName(“TYPE-DESCRIPTION”)[0].firstChild.data, subTypeList[i].getElementsByTagName(“TYPE”)[0].firstChild.data);
}
}
else if(status==’FAILURE’)
{
alert(xmlMessage.getElementsByTagName(“MESSAGE”)[0].firstChild.data);
}
}
catch(e)
{
alert(“Problem in handling request “+e);
}
}
System.out.println(“Response “+xmlMessage);
response.setContentType(“application/xml”);
response.getWriter().write(xmlMessage);
response.getWriter().flush();
response.flushBuffer();
return null;
bipien@yahoo.comMemberRe: cant understand code
-
AuthorPosts