.load not working with JSON data (std works, pro doesn't)

I have a simple form that loads JSON data. It worked fine with DHTMLX standard version. I purchased the current version now it doesn’t work. No errors are reported, fields won’t load data.

myForm.load(‘data.php?method=accidentReportGet&id=’+id, “json”);

The data is successfully coming back formatted like this…

{“id”:“11”,“custid”:“3”,“doctype_id”:“3”,“docno”:“ACC2013-11”,“status”:“OPEN”,“createdate”:“2013-07-29 16:11:46”,“createdbyuserid”:“678”,“accdate”:null,“vehicleno”:null,“driver”:null,“aide”:null,“supernotified”:null,“supersent”:null,“supervehicle”:null,“damage”:“0”,“towtruck”:“0”,“injuries”:“0”,“policeonscene”:“0”,“rescuesquad”:“0”,“location”:null,“roadconditions”:null,“remarks”:null}

Why won’t it load the data into the fields now that I purchased the pro version?

I also tried changing all the :null json values to :"" , that didn’t work either.

I got it working by doing it this way…

var loader = dhtmlxAjax.getSync("data.php?method=accidentReportGet&id=" + id + "&etc=" + new Date().getTime()); myForm.setFormData($.parseJSON(loader.xmlDoc.responseText));
However, I would expect the purchased version of DHTMLX to be able to load a JSON string all on it’s own. I should not have to use the jQuery.parseJSON() function. Let me know if there’s a better way to accomplish this. Thanks.

hi

please provide completed demo including all corresponding js/css files or direct link to reproduce issue. you also can send it to support@dhtmlx.com

I solved this problem as follows:

the function prototype load “dhtmlXForm.prototype.load = function (url, type, callback)” after evaluating json u should add setFormData

var data = {};
if (type == “json”) {
eval (“data =” + loader.xmlDoc.responseText) form.setFormData (date);
}

Full function below :

dhtmlXForm.prototype.load = function(url, type, callback) {
var form = this;
form.callEvent(“onXLS”,[]);

if (typeof type == 'function'){
	callback = type;
	type = 'xml';
}

dhtmlxAjax.get(url, function(loader){
	var data ={};
	if (type == "json"){
		eval("data="+loader.xmlDoc.responseText);form.setFormData(data);
	}
    else {
		var top = loader.doXPath("//data")[0];
		if (top && top.getAttribute("dhx_security"))
			dhtmlx.security_key = top.getAttribute("dhx_security");
		var tags = loader.doXPath("//data/*");
		for (var i=0; i < tags.length; i++) {
			data[tags[i].tagName] = tags[i].firstChild?tags[i].firstChild.nodeValue:"";
		};
	}		
	
	var id = url.match(/(\?|\&)id\=([a-z0-9_]*)/i);
	if (id && id[0])
		id = id[0].split("=")[1];	
		
	if (form.callEvent("onBeforeDataLoad", [id, data])){
		form.formId = id;
		form._last_load_data = data;
		form.setFormData(data);
		form.resetDataProcessor("updated");
	}
	
	//after load callback
	form.callEvent("onXLE",[]);	
	if (callback) callback.call(this);
});

};

Hi

localy works fine, as I already said - please provide demo to reproduce localy or link

setFormdata called in onBeforeDataLoad below, also some more logic

if (form.callEvent(“onBeforeDataLoad”, [id, data])){

setFormData()

adding setFormData rigth after json parsing will broke onBeforeDataLoad if it used