XMLHttpRequest and IE 8 error - in jsp/servlet applicaton

Posted by Greener on Stack Overflow See other posts from Stack Overflow or by Greener
Published on 2010-04-01T20:10:52Z Indexed on 2010/04/01 20:13 UTC
Read the original article Hit count: 538

Filed under:
|
|

Hello, I am using HMLHttpRequest object to retrieve information from the database via servlet and populate combo box. The code run in Firefox 3.6 and Chrome without any problems. However, I have a problem with IE 8. here is my code:

var req;
var isIE;

 function initRequest(){
     if (window.XMLHttpRequest) {
                req = new XMLHttpRequest();
            } else if (window.ActiveXObject) {
                isIE = true;
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
    function populateMuniBox(countyCode)
        {
            initRequest();
            req.onreadystatechange = populateMuniCallback;
            req.open("GET","./CntyMuni?county="+ countyCode,true);
            req.send(null);
       }

  function populateMuniCallback()
      {
          //clean combo box
          document.getElementById("cmbMuni").options.length = 0;

          var muni;

          if(req.readyState==4){
              if (req.status == 200){
               var XMLresult = req.responseXML;
               var muni = XMLresult.getElementsByTagName("rec");
              }
           }

          for(var i=0;i<muni.length;i++)
            {
                //create Html option Element  
                var opt = document.createElement("option"); 
                //Set up the option - add values from XML 
                opt.value = muni[i].getAttribute("code");
                opt.text = muni[i].getAttribute("desc");
                //add the option to the combobox
                document.getElementById("cmbMuni").appendChild(opt);
            }

      }
  HMTL code
  //First combo box the sends a value to the script
     <td>    <select name="cn" id="county" onchange="populateMuniBox(this.value)">
  // Second cmb 
       <select name="mu" id="cmbMuni" ></select>

IE error: 'lenght' is null or not an object cntymuni.jsp Code: 0
I am not sure how to fix the error.

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about jsp