468,107 Members | 1,337 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

problem with the Ajax responseText in Mozilla

RamananKalirajan
607 512MB
Hi All,
I am using Ajax inorder to retrieve a data from the db which is an xml and i am parsing the responseText into an xml. the code what i had tried is working well with IE, but the same makes a lot of trouble in mozilla any help would be greatful

the following is the code

[HTML] if (httpRequest.readyState == 4)
{
if(httpRequest.status == 200)
{
var pricingSummaryXML = httpRequest.responseText;
alert("Pricing Summary XML = "+pricingSummaryXML);
var xmlDoc = newXMLDoc(pricingSummaryXML);
alert("XML Doc = "+xmlDoc);
if(xmlDoc != null)
{
var root = xmlDoc.getElementsByTagName("response")[0]; //This line shows Error[/HTML]

[HTML]function newXMLDoc(xmlData)
{
var xmlDoc = null;
try { //Internet Explorer
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
alert("Inside 1");
xmlDoc.loadXML(xmlData);
}
catch(e)
{
try {
//Firefox, Mozilla, Opera, etc.
parser=new DOMParser();
alert("Inside 2")
xmlDoc=parser.parseFromString(xmlData,"text/xml");
}
catch(e) {
alert(e.message);
return null;
}
}
return xmlDoc;
} [/HTML]

In mozilla I am getting an exception with the description root is null, i tried it by displaying its length, it shows 0. I replaced the responseText with the XML directly what I am retrieveing from db it works but i want in the responseText only. Please i need some suggestions

Regards
Ramanan Kalirajan
Sep 16 '08 #1
4 2350
Atli
5,058 Expert 4TB
Hi.

Have you tried using the responseXML property?

Like:
Expand|Select|Wrap|Line Numbers
  1. xmlDoc = request.responseXML;
  2.  
  3. // Get a list of <node> nodes
  4. nodes = xmlDoc.getElementsByTagName('node');
  5.  
  6. // Print the value of each <node>
  7. for(i = 0; i < nodes.length; i++) {
  8.     alert(nodes[i].childNodes[0].nodeValue);
  9. }
  10.  
Sep 16 '08 #2
RamananKalirajan
607 512MB
Hi.

Have you tried using the responseXML property?

Like:
Expand|Select|Wrap|Line Numbers
  1. xmlDoc = request.responseXML;
  2.  
  3. // Get a list of <node> nodes
  4. nodes = xmlDoc.getElementsByTagName('node');
  5.  
  6. // Print the value of each <node>
  7. for(i = 0; i < nodes.length; i++) {
  8.     alert(nodes[i].childNodes[0].nodeValue);
  9. }
  10.  
I am sorry I am not having any idea on responseXML, wether it is available with normal Ajax or Prototype Ajax, since u had specfied with request.responseXML. pls tell me wether can i use it in normal ajax i.e. in httprequest

Regards
Ramanan Kalirajan
Sep 16 '08 #3
Dormilich
8,651 Expert Mod 8TB
you can use responseXML in normal AJAX (it's one of the standard properties: ajax methods and properties (scroll down a bit))

regards
Sep 16 '08 #4
Atli
5,058 Expert 4TB
Yea. It's a part of the XMLHttpRequest object. (Note the XML part ;P)
Should be available on any browser that supports AJAX.

I've noticed, however, that if the requested file doesn't specify the Content-Type as "text/xml" (excluding actual .xml files), the responseXML property will be undefined.
Just something to keep in mind if your generating the XML using a server-side language.
Sep 16 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Stephen | last post: by
1 post views Thread by mauroalberti | last post: by
2 posts views Thread by Seguros Catatumbo | last post: by
1 post views Thread by diaboliko80 | last post: by
1 post views Thread by geevaa | last post: by
7 posts views Thread by RaefKandeel | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.