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!

Obtaining dynamic XML

Status
Not open for further replies.

tcstom

Programmer
Aug 22, 2003
235
GB
I'm fairly new to AJAX and having trouble with responseXML. My Javascript opens an HTTP request which calls an ASP.NET page. This page has been configured to return valid XML using .NET's XmlTextWriter class, but the result only seems to be available to the AJAX script as the responseText of the HttpRequest rather than the responseXML. It looks to me that to return an XML document in the responseXML then the file that is requested must have an XML extension. Am I right? If so, is there any other way to obtain a dynamically generated XML document with AJAX? Failing this, is there a way to convert the responseText to XML?
 
Thanks for the link but it doesn't answer my question. I'm just using HTTP GET. The requested URL is an ASPX file (not XML) but it only contains valid XML and is of text/xml content type. However, http_request.responseText returns this XML as text (which therefore I can't parse using the DOM) and http_request.responseXML returns nothing.
 
have you copy pasted the XML to a file with an XML extension and used a GET method on that file to test if the extension is the issue?

also why do you say
http_request.responseText returns this XML as text
isn't XML text?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Yes, if I save the ASPX output an an XML file it works fine. Yes, XML is text, but http_request.responseXML returns a parsable XML document whereas responseText just returns plain text. Anyway, I've got round this issue now by using the Javascript DOMParser object to parse this plain text as an XML document. This isn't available to IE though so you need to impersonate it using the code I've found here:
Thanks anyway.
 
cool glad you got it, it may be that the XMLHttpRequest class uses the extension to identify the content type.

However I have found this piece of code which may help you to force the returned result into being treated as XML, it might help you.
Code:
http_request = new XMLHttpRequest();
[b]http_request.overrideMimeType('text/xml');[/b]

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
No, I've already overridden the MIME type. Still, my solution works. Thanks for helping out.
 
sorry i couldn't help more :-(

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top