JSON Format Server Return Data

Hi,

As (in another thread) I’m having issues / conflicts between dhtmlx connector and an auth library, have started to look into building my own server code. Have decided to return JSON and went with some examples (from .load() method) of the JSON format required. Here is my php code:

[code] $conn = mysql_connect($mysql_host,$mysql_user,$mysql_pasw);
mysql_select_db($mysql_db);

$result = mysql_query("SELECT name,description,created,project,taskid FROM tasks2 WHERE project=".$id);

while($obj = mysql_fetch_object($result)) {
$arr[] = $obj;
}
echo '{"data":'.json_encode($arr).'}';[/code]

This seems to return data in the correct format, as in:

{“data”:[{“name”:“steve”,“description”:“test description this is”},{“name”:“another name”,“description”:“yet another description”}]}

But still no display in the listview (previously working when using connector to return XML). Have attempted to set the second parameter of thje load() method to both ‘js’ and ‘json’ despite docs saying auto connect yet still no joy.

Any ideas on this at all ?

Thanks in advance,

Steve

Be sure that you are using load command with second parameter set as “js”

myGrid.load("data.json", "js");

Also, you need to use setColumnIds command with IDs equal to names of fields in the json

docs.dhtmlx.com/api__link__dhtml … mnids.html

Stanislav,

Thanks for the response.

I had tried the second param ‘js’ as mentioned previously.

As for the column id’s, should have mentioned that I am using DataView on the page - isn’t mapping done from the template direct to the json ? i.e. is there still a need for this when using the dataview ?

Thanks :slight_smile:

Steve

For dataview you can use

dv.load(url,"json") 

without any extra mapping.

also, the data must be just an array, without the wrapping object

[{"name":"steve","description":"test description this is"},{"name":"another name","description":"yet another description"}]