Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getElementsByTagName + IE

Status
Not open for further replies.

vlitim76

Programmer
Jun 1, 2006
19
GB
I am using Ajax and have got it working in Firefox but IE doesn't seem to fill the getElementsByTagName array correctly

Below is the end function that gets the data. the xml that is returned to it is

<valid>true</valid>

Code:
function checkDuplicateCaseNo(responseXML)
{

    var msg = responseXML.getElementsByTagName("valid")[0].firstChild.nodeValue;
    if (msg == "false") 
    {
        alert("No")
    }
}

and this is the httprequest part

Code:
function makeHttpRequest(url, callback_function,param, return_xml) 
{ 
   var http_request = false; 

   if (window.XMLHttpRequest) { // Mozilla, Safari,... 
       http_request = new XMLHttpRequest(); 
       if (http_request.overrideMimeType) { 
           http_request.overrideMimeType('text/xml'); 
       } 
   } else if (window.ActiveXObject) { // IE 
       try { 
           http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
       } catch (e) { 
           try { 
               http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
           } catch (e) {} 
       } 
   } 
   if (!http_request) { 
       alert('You browser doesn\'t support this feature.'); 
       return false; 
   } 
   http_request.onreadystatechange = function() { 
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
               if (return_xml) { 
                   eval(callback_function + '(http_request.responseXML,param)'); 
               } else { 
                   eval(callback_function + '(http_request.responseText,param)'); 
               } 
           } else { 
               alert('There was a problem with the request.(Code: ' + http_request.status + ')'); 
           } 
       } 
   }
   url = url + '&xml=1&ms='+new Date().getTime()
   http_request.open('GET', url, true); 
   http_request.setRequestHeader('REFERER', document.location);
   http_request.send(null); 
}

 
Ah. It's probably because valid is not a valid tag name... unless of course you are returning a full DTD etc for your XML. Most likely you are not.

I suggest you change your code to return HTML-valid tags:
Code:
<div>false</div>

An alternative may be to avoid using getElementsByTagName and instead walk the node tree and and query the node type etc manually.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
The problem may be the reply from the server. I had the same problem until I added:

header("Content-type: text/xml");

to the PHP file on the server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top