Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

javascript request.responseXML

Posted on 2009-07-05
9
788 Views
Last Modified: 2012-05-07
Using alert I can see "textDoc" but NOT "xmlDoc"
Does this mean I am not getting an xml document returned in "request.responseXML"
request = createRequest();
 request.open("GET", "http://www.AmericanMarketingGroup.net/ws/get_date_time.asp", false);
 request.send(null);
 if (request.readyState == 4) {
if (request.status == 200) {
var responseDoc = request.responseXML;
var textDoc = request.responseText;			
var xmlDoc = responseDoc;
alert("Status:"+request.status+"\nText Length:"+textDoc.length+"\nText:"+textDoc+"\nXML Length:"+xmlDoc.length+"\nXML:"+xmlDoc);

Open in new window

0
Comment
Question by:MikeCombe
  • 6
  • 2
9 Comments
 
LVL 9

Expert Comment

by:AsishRaj
ID: 24782411
0
 

Author Comment

by:MikeCombe
ID: 24782587
sorry....all four points we evaluated but was not the problrm.
anything else ?
0
 
LVL 2

Expert Comment

by:laurent_roy
ID: 24783905
no the first point is not validated !
You have to add an http header : "Content-Type:text/xml"
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:MikeCombe
ID: 24785856
yes I did that already...the original code snipet doen't show it. I tried it both ways, with & without it.
Below is the Revised code snippet.


= = = = = = = Revised code snippet = = = = = 
 
request = createRequest();
request.open("GET", "http://www.AmericanMarketingGroup.net/ws/get_date_time.asp", false);
request.setRequestHeader("Content-Type", "text/xml");
request.send(null);
if (request.readyState == 4) {
if (request.status == 200) {
var responseDoc = request.responseXML;
var textDoc = request.responseText;			
var xmlDoc = responseDoc;
alert("Status:"+request.status+"\nText Length:"+textDoc.length+"\nText:"+textDoc+"\nXML Length:"+xmlDoc.length+"\nXML:"+xmlDoc);

Open in new window

0
 

Author Comment

by:MikeCombe
ID: 24785931
making these changes...makes the "xml length" display different values...

var xmlDoc = request.responseXML;                            //<-- xml length=undefined
//var xmlDoc = request.responseXML.xml;      //<-- xml length=0

= = = = = = = Revised code snippet = = = = = 
 
request = createRequest();
request.open("GET", "http://www.AmericanMarketingGroup.net/ws/get_date_time.asp", false);
request.setRequestHeader("Content-Type", "text/xml");
request.send(null);
if (request.readyState == 4) {
if (request.status == 200) {
var responseDoc = request.responseXML;
var textDoc = request.responseText;	
		
var xmlDoc = request.responseXML;	         //<-- xml length=undefined
//var xmlDoc = request.responseXML.xml;	//<-- xml length=0
 
alert("Status:"+request.status+"\nText Length:"+textDoc.length+"\nText:"+textDoc+"\nXML Length:"+xmlDoc.length+"\nXML:"+xmlDoc);

Open in new window

0
 
LVL 2

Expert Comment

by:laurent_roy
ID: 24786403
you don't have to put the header in the request but in the response, that is to say in get_date_time.asp.
0
 

Author Comment

by:MikeCombe
ID: 24787157
nope...
put ("Content-Type", "text/xml") into the header of the generating xml page....same response as before.
0
 

Accepted Solution

by:
MikeCombe earned 0 total points
ID: 24789101
= = = = = SOLUTION = = = =
Here's the solution. An "object" needs to be created...then that object can be worked with.

var xmlDoc = request.responseXML;
needs to be changed to
var xmlDoc = request.responseXML.documentElement;

Now you have an object named xmlDoc

With that object we can start using it...
alert(xmlDoc.xml);
alert("xml length = " + xmlDoc.xml.length);.





var xmlDoc = request.responseXML.documentElement;
 
alert(xmlDoc.xml);
 
alert("Status:"+request.status+"\nText Length:"+textDoc.length+"\nText:"+textDoc+"\nXML Length:"+xmlDoc.xml.length+"\nXML:"+xmlDoc.xml);		

Open in new window

0
 

Author Closing Comment

by:MikeCombe
ID: 36275239
self-discovered
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question