PDA

View Full Version : IE error parsing xml from Basic Ajax Routine



kevin_dalby
01-24-2008, 12:20 PM
1) Script Title: Basic Ajax Routine

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm

3) Describe problem:

I used the Basic Ajax script to fetch some XML data based on the user selecting a value from a drop down list - when the XML returns I can see it looks correct via the Alert function. At the end of the function I push the XML values to the fields in a form on the page.

This code works properly in Firefox.:)

In IE I get an error - Object Required which occurs on the line that begins document.forms..

I think it is complaining about myvirtdoc.getElementsByTagName part since I can put in a static string on the right side of the '=' sign and IE stops complaining.

Can anyone help me out by explaining why IE doesn't like this and how to fix it.



<script type="text/javascript" >

// function to make ajax request and then push values to field forms

function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
myvirtdoc=(myajax.responseXML)

// push values to form
document.forms["recSurvTime"].CustRate.value= (dropped down for clarity)
myvirtdoc.getElementsByTagName("custrate")[0].childNodes[0].nodeValue;

}
}
}
</script>

thanks,
Kevin