?
Solved

javascript request.responseXML

Posted on 2009-07-05
9
Medium Priority
?
800 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
[X]
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
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

752 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