Jump to content

Ajax And Ie8


johnnyg24

Recommended Posts

I am having a problem with an AJAX request and IE8. I am requesting an XML document as follows:

var shipto = false	if(window.XMLHttpRequest) {		shipto = new XMLHttpRequest();			if(shipto.overrideMimeType){			   				shipto.overrideMimeType("text/xml");			}	 	}else if (window.ActiveXObject) {		shipto = new ActiveXObject("Microsoft.XMLHTTP")	}function getShipto(){	if(shipto){		shipto.open("GET", '/webwiz/wwiz.asp?wwizmstr=W_GET_SHIPTO_XML', true);		shipto.onreadystatechange = function(){			if(shipto.readyState == 4 && shipto.status == 200) {				//do something			}		}		shipto.send(null);	}}

If I look at the responseText in IE8, I can see the XML document. However, I need the responseXML and IE8 keeps saying object required every time I try and extract data from it. This is how I am trying to extract the data:

var obj = shipto.responseXMLobj.getElementsByTagName("stname")[0].firstChild.data

am I doing something wrong? Any help would be great. Thank you.

Link to comment
Share on other sites

I wish I knew more about this. To learn more about your object, I would examine what I have:alert (shipto.responseXML); alert (shipto.responseXML.documentElement); And if that didn't work, I'd see if shipto.responseXML had any properties:alert (shipto.responseXML.length);and if it did, I'd loop through them:var str = "";for (var p in shipto.responseXML) {str += p + "<br>\n";}And then either alert(str) or, if it turns out to be long, write the string into a textarea or something.

Link to comment
Share on other sites

I've tried all of those. The only method that returns any response other than "null" or "undefined" is shipto.responseXML. When I use that, the alert says "[object]". But when I go to find the length of one of the tagNames, it returns 0 while FF returns 2. I know FF is returning the correct length because I know there are only two tags in this particular XML document with the tagName I am specifying.This XML document is being generated on our server. I recreated the XML document and saved it as 'test.xml' and then pointed the AJAX request to that page, everything worked fine in both FF an IE. I am starting to think it has something to do with coming from our server. However, I have no idea where to begin to try and find out what the problem is. Do you know of any ways I can test the server generated XML to see if by chance it is not constructed properly. Keep in mind that FF and Chrome both are able to use the server generated XML. This then makes me believe that it is just an IE thing.

Link to comment
Share on other sites

Actually, I think IE might be doing it correctly... which isn't that surprising, considering that they pioneered XMLHttpRequest (well... as an ActiveX control originally, but still).As suggested by Deirdre's Dad, you need to make your server (ASP) script send the output with the XML MIME type. Which reminds me - it shoud be application/xml, not text/xml.So... after replacing "text/xml" with "application/xml" in your JavaScript, in your ASP file, call Response.ContentType with "application/xml" as its argument, and do so before outputting anything.

Link to comment
Share on other sites

Unfortunately we use a third party software that writes our .asp pages. We do this so our IT personal doesn't have to learn a new scripting language and can write BASIC programs and subroutines that are then converted to .asp by this third party software. So the content type is being set to "text/xml". Is there any way that I can change "text/xml" to "application/xml" after our server sends the .xml document?

Link to comment
Share on other sites

Is there any way that I can change "text/xml" to "application/xml" after our server sends the .xml document?
Isn't the overrideMimeType property used for that? Though I'm not sure if IE supports it. After the portion
if(shipto.overrideMimeType){			   				shipto.overrideMimeType("text/xml");			}

add

else {alert("Your browser doesn't support 'overrideMimeType'");}

And if you see the alert, we're in trouble... and I'm not (yet) sure how to proceed. If you don't see the alert, just change "text/xml" to "application/xml", and it should be OK.

Link to comment
Share on other sites

Ok, I found the answer. While this does not work in IE:

function getShipto(){var shipto = false	if(window.XMLHttpRequest) {		shipto = new XMLHttpRequest();	}else if (window.ActiveXObject) {		shipto = new ActiveXObject("Microsoft.XMLHTTP")	}	if(shipto){		shipto.open("GET", '/webwiz/wwiz.asp?wwizmstr=W_GET_SHIPTO_XML', true);		shipto.onreadystatechange = function(){			if(shipto.readyState == 4 && shipto.status == 200) {				var nameText =  shipto.responseXML.getElementsByTagName("stname")name[0].firstChild.nodeValue				alert(nameText)			}		}		shipto.send(null);	}}

this does work in IE:

function getShipto(){var shipto = false	if(window.XMLHttpRequest) {		shipto = new XMLHttpRequest();	}else if (window.ActiveXObject) {		shipto = new ActiveXObject("Microsoft.XMLHTTP")	}	if(shipto){		shipto.open("GET", '/webwiz/wwiz.asp?wwizmstr=W_GET_SHIPTO_XML', true);		shipto.onreadystatechange = function(){			if(shipto.readyState == 4 && shipto.status == 200) {				var newXML = shipto.responseXML				var name = newXML.getElementsByTagName("stname")				var nameText = name[0].firstChild.nodeValue				alert(nameText)			}		}		shipto.send(null);	}}

I don't know why but it does. Thanks for everyone's help.Edit: Sorry, I think it is actually because I am using 'firstChild.nodeValue' instead of 'firstChild.data'

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...