Solved

XMLhttp.responseXML contains different data than XMLhttp.responseText after replaceChild

Posted on 2008-10-25
5
2,511 Views
Last Modified: 2012-06-27
I am try to create a page that allows users to view XML data, edit the data, and save it. I am using javascript to do most of it, and PHP to save. I have it working for the most part. I get the edited information, and use replaceChild to update the database. I want to then pass this new XML to PHP to save it on the server. I use XMLhttp.responseText to get the text version of the XML to pass to PHP. But when I display teh responseText, it is the old data. When i look at the responseXML using firebug, it is updated with the new data. Why doesn't responseText update with responseXML? The server is on a Debian Linux system. I have tried this script on both Linux and windows using firefox and IE, both react the same way. should responseText update when responseXML changes? Or do I need to do something to get it updated?
0
Comment
Question by:steinermann
  • 4
5 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22805531
If you want the string version, can you not do this:

var responseText = responseXML.toString();
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22805610
I have a feeling that the above will display something like "object Element".

The following works in IE...I am trying to find a firefox compatible solution
var responseText = responseXML.documentElement.xml;
0
 
LVL 13

Accepted Solution

by:
numberkruncher earned 125 total points
ID: 22805619
This should do the trick...
var responseText = responseXML.documentElement.xml; // IE

if (!responseText) { // FF, Chrome, Safari

   var s = new XMLSerializer();

   responseText = s.serializeToString(responseXML.documentElement);

}

if (!responseText) {

    // Error, not supported.

}

Open in new window

0
 

Author Closing Comment

by:steinermann
ID: 31510014
Thank you. That worked perfect. I can't beleive I missed that. Any idea why xmlhttp.responseText and xmlhttp.responseXML were not the same?
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22816437
From what I have read on the subject, generally responseText is available when the returned content is "text/plain" and responseXML when the returned content is "text/xml" or "application/xml". Of course you can convert between the two if you are happy that the information is actually XML.

If your using the Prototype framework, then responseJSON is available when the content is "application/json". (http://www.prototypejs.org) I often use this instead of XML because it is faster to parse at the client. If you are interested in JSON, there is a lot of information available at the prototype website.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…

708 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

16 Experts available now in Live!

Get 1:1 Help Now