PDA

View Full Version : responseText and ersponseXML


otnj2ee
01-16-2008, 10:29 PM
from javascript made AJAX call-->

-->Server side:

String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><options><option>Test</option></options>";

response.getOutputStream().println(xmlString);


-->Now back to javascript:

var optsArray = ajaxRequest.responseXML.getElementsByTagName('option');
for(var i=0; i<optsArray.length; i++) {
...
...

It works fine. Since it returns a string from server side I would assume I should use ajaxRequest.responseText, and ajaxRequest.responseXML should not work. But in reality, ajaxRequest.responseXML works just fine.

Why and how does it (ajaxRequest.responseXML) work for a returned string?


Thanks

Scott

shyam
01-17-2008, 03:02 AM
if u view the server-side script in a browser does it display as simple text or does it display xml?

A1ien51
01-17-2008, 05:11 AM
I think you are really over thinking things.

Sort of like saying I wrote my XML document in notepad so it is really a text file and not an xml file.

As long as the string is correctly formatted XML and you set the right content type, the browser will see it as XML. It does not care how it was created or where it came from.

Eric