facebook

cant understand code

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #300403 Reply

    // 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;

    #300415 Reply

    Re: cant understand code

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: cant understand code

You must be logged in to post in the forum log in