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
Solved

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

Posted on 2008-10-25
5
2,543 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Jquery-Javascript setAttribute function help 7 18
Create an automated page index 9 47
Insert Button on a table 16 37
Html Newline 7 20
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-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

809 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