Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-25
5
Medium Priority
?
2,568 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

670 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