Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

javascript request.responseXML

Posted on 2009-07-05
9
Medium Priority
?
812 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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 discusses how to implement server side field validation and display customized error messages to the client.
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…

610 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