Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Michael on Dec 29, 2008 12:31
open dhtmlx forum
dhtmlxAjax - reponseXML node values

When I use standard ajax calls, I can implement the following code to retrieve a value from a specific node of the ResonseXML object.

var xmlDoc=xmlHttp.responseXML.documentElement;
document.getElementById("companyname").innerHTML= xmlDoc.getElementsByTagName("compname")[0].childNodes[0].nodeValue;

I have been unsuccessful implementing similar code with the loader.xmlDoc.responseXML property. Is it possible?
Answer posted by Support on Dec 29, 2008 16:09
The dhtmlxAjax just a wrapper around xmlHTTP Object so you can use the same methods as against native xmlHTTP object.

>>xmlHttp.responseXML.documentElement
dhtmlxAjax.get(url,function(obj){
    alert(obj.xmlDoc.responseXML.documentElement.getElementsByTagName("compname")[0].childNodes[0].nodeValue);
})

beware that documentElement property supported not in all browsers, the same can be written as
    obj.doXPath("//compname")[0].firstChild.nodeValue
Answer posted by Michael on Apr 01, 2009 14:21

I still cannot get this to work. 

I am doing an dhtmlxAjax.post() and I am outputting the following:

echo "<?xml version='1.0' encoding='utf-8'?><post><param name='success'>true</param><param name='type'>UsersToRole</param></post>";

and the following gives me errors in my callback function.

alert(loader.doXPath("//success")[0].firstChild.nodeValue);

and this also gives me errors.

alert(loader.xmlDoc.responseXML.documentElement.getElementsByTagName("success")[0].childNodes[0].nodeValue);

but this works.

alert(loader.xmlDoc.responseText);

why?

 

Answer posted by Support on Apr 03, 2009 07:58
Please try to use debug version of dhtmlxcommon.js 

http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&q=2545&ssr=yes&s=dhtmlxcommon

The most common reasons of similar problems

- content was send with incorrect content type ( Content-type:text/xml required to operates with response as with XML on client side ) 
- in case of FF , any whitespace before <?xml declaration will prevent correct client side parsing. 

Answer posted by Michael on Apr 03, 2009 08:43
What exactly is the debug file supposed to show me?  It does not do anything different from the normal dhtmlxCommon.js file as far as I can tell.  I included it in my page and used it.  I thought I was supposed to get debug info?
Answer posted by Michael on Apr 03, 2009 08:56
Here is the test code I am running.  Retrieving the responseText works, but the other 2 alerts do not.
Attachments (1)
debug.zip7.37 Kb
Answer posted by Support on Apr 03, 2009 09:43
To fix problem, change the next line in php file 
    header("Content-type: application/xhtml+xml");
to the
    header("Content-type: text/xml");


It will fix error in IE ( sample already works correctly in FF ) 

>>What exactly is the debug file supposed to show me?
Actually it must catch incorrect content type error and show related message , but somehow it failed, it seems while it can detect error for xml loading inside components it not good for separate dhtmlxAjax call - we will update it in nearest time. 
Answer posted by Michael on Apr 03, 2009 09:49

Thank you.  That fixed it. 

But why did I need to change the header from header("Content-type: application/xhtml+xml") to header("Content-type: text/xml")?  I use the first form of header throughout my entire site for grids and trees etc and have not had any problems with them. 

Does dhtmlxAjax control work differently than those other controls?