Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

831 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