Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-25
5
Medium Priority
?
2,573 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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

877 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