Solved

javascript request.responseXML

Posted on 2009-07-05
9
783 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
Comment Utility
0
 

Author Comment

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

Expert Comment

by:laurent_roy
Comment Utility
no the first point is not validated !
You have to add an http header : "Content-Type:text/xml"
0
 

Author Comment

by:MikeCombe
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:MikeCombe
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
= = = = = 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
Comment Utility
self-discovered
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now