I don’t think this is the right thread, but I don’t know where to put it otherwise.
I’m using dhtmlxajax version 4.1.2.
I’m trying to get data from the server via dhtmlxajax using following code:
function ajaxRequest(url) {
window.dhx4.ajax.get(url, ajresponse);
}
function ajresponse(r){
var xml = r.xmlDoc.responseXML;
if (xml != null) {
// response successfuly parsed
var root = xml.getElementsByTagName("response")[0];
var day=root.getAttribute("day");
var error=root.getAttribute("error");
var dataroot=xml.getElementsByTagName("data")[0];
var data=dataroot.getAttribute("cdata");
//... some other code
} else {
// response is not in xml format
}
}
This is an example of the data I get back from the server:
Can anyone explain me how to get the cdata back via xml?
Is my xml wrong or am I using the wrong code? There isn’t much documentation online about this…
Here is the code I use for future reference and to help someone else who is struggling with the same problem:
xml:
[code]<?xml version="1.0" ?>
<![CDATA[
16/02/2015
17/02/2015
]]>
[/code]
Javascript:
function byId(id) {
return document.getElementById(id);
}
function ajaxRequest(url,data) {
url = url + "?"+data;
dhx4.ajax.get(url, getResponse);
}
function getResponse(r) {
var xml = r.xmlDoc.responseXML;
var res = byId("result");
if (xml != null) {
// response successfuly parsed
var response = xml.getElementsByTagName("response")[0];
var error = response.getAttribute("error");
var html= "";
if (error=="0"){
html=response.firstChild.nodeValue;
}
else{
html="There was an error.";
}
res.innerHTML=html;
}
else {
// response is not in xml format
res.innerHTML="Result not in xml format.";
}
}
This is filled with the value from res.innerHTML, just put it somewhere in the body:
<div id='res'<div>
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan