How to get sections from DB in Unit view.

Until now for list of sections I was using this and it was working as intended

var sections = [{ key: 1, label: 'Prva soba' }]

I now want to get sections from DB. I have used this code for that

$.ajax({ url: "naziv.asmx/RoomListUnit", data: "{ 'skolaID': 'some ID goes here'}", dataType: "json", async: false, type: "POST", contentType: "application/json; charset=utf-8", dataFilter: function (data) { return data; }, success: function (data) { sections = data.d.toString(); } });
It is not working. When I try alert(sections) the data is good. But sections are not loading on unit view

Sections need to be defined before unit-view creation

Why not use common data loading scheme, which can load sections as part of data? … _from_json … #connector

TBH I didn’t know how to use it because I have custom .net handler, but after some googling I found solution that was so simple that I wanted to slap myself for loosing so much time on this problem.

success: function (data) { sections = (new Function("return " + data.d))(); }