Solved

javascript request.responseXML

Posted on 2009-07-05
9
792 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

690 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