jQWidgets Forums
jQuery UI Widgets › Forums › Layouts › Docking › Invalid json
Tagged: cookie, docking, importLayout, Invalid, jqxDocking, json
This topic contains 10 replies, has 2 voices, and was last updated by Dimitar 10 years, 5 months ago.
-
AuthorInvalid json Posts
-
Hi,
Is it possible that the having cookies set on an ip address based domain is unsupported? I’m getting an error saying invalid json when i have set cookies to true.
From the google developer tools i got the below cookie content:
%7B%22panel0%22%3A%20%7B%22jqxWidgetea58560b%22%3A%7B%22collapsed%22%3Afalse%7D%2C%22jqxWidgete8823f3f%22%3A%7B%22collapsed%22%3Afalse%7D%7D%2C%22panel1%22%3A%20%7B%22jqxWidgetb0b3aa75%22%3A%7B%22collapsed%22%3Afalse%7D%7D%2C%22panel2%22%3A%20%7B%22jqxWidget3a99d280%22%3A%7B%22collapsed%22%3Afalse%7D%7D%2C%22floating%22%3A%7B%7D%2C%22orientation%22%3A%20%22horizontal%22%7D
Hello John,
Could you, please, clarify how is your issue related to jqxDocking? Is this the JSON you use in importLayout? If so, please post an example we can test to reproduce the issue.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
I’m using the following code:
<div id="favoriteblock" style="max-height: 500px;margin-left: 0px; overflow-x:hidden; overflow-y:auto;"> <div id="favoriteblock_0"></div> <div id="favoriteblock_1"></div> <div id="favoriteblock_2"></div> </div>
$.get('/jsonrpc.json?rpc={"jsonrpc": "2.0", "method": "DeviceService.getFavoriteDevices","id":"DeviceService.getFavoriteDevices"}').done(function(data) { try { var curBlock; for(var i=0;i<data.result.data.length;i++){ var device = data.result.data[i]; curBlock = '#favoriteblock_' + i%3; $(curBlock).append('<div class="favitemdock"><div><div onclick="refreshPageContent(\'/desktop/devices.html?deviceLink='+device.id+'\')" style="cursor:pointer; line-height:17px;">'+device.friendlyname+'</div></div>\n\ <div>\n\ <div style="min-height:50px; padding-bottom:0px;">\n\ <img src="" id="fav_img_'+device.id+'" alt="'+device.friendlyname+'" style="float:left;"/>\n\ <table style="float:left;margin-left:5px;" id="fav_'+device.id+'"></table>\n\ <div style="clear:both;"></div>\n\ </div>\n\ </div></div>'); composeDeviceVisuals('fav_'+device.id, device, false, true, true); setDeviceCatImage('fav_img_'+device.id, device.categoryconstant); } $("#favoriteblock").jqxDocking({ cookieOptions: { expires: 3600 }, cookies: true, mode: 'docked', orientation: 'horizontal', width: 820, theme: siteSettings.getTheme()}); $("#favoriteblock").jqxDocking('hideAllCloseButtons'); $('#favoriteblock').jqxDocking('showAllCollapseButtons'); } catch (err){ alert(err); } });
All the docked items appear as they should, The error pops up when cookies are set to true, i have also tried to set cookie options host to the ip address where the page runs. When cookies are set to false the message is gone.
This is the one and only item on the whole site that places a cookie. and the above string is this cookie contents. When i remove the cookie and have set cookies to false, no cookies are set.
There is an alert(err) in the catch block, but when removed the JSON error still appears.
Best regards,
John.The below is when i export a layout
{"panel0": {"jqxWidget3ca77739":{"collapsed":false}, "jqxWidget0c82ec80":{"collapsed":false}}, "panel1": {}, "panel2": {"jqxWidget3138414c":{"collapsed":false}, "jqxWidget1ffc446d":{"collapsed":false}}, "floating":{}, "orientation": "horizontal"}
Hi John,
Could you, please, provide us with the JSON response you got from the external service so that we may see if it is correct?
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
The following is the output from the external service
{ "jsonrpc": "2.0", "id": "DeviceService.getFavoriteDevices", "result": { "data": [ { "friendlyname": "Rasp server", "locationname": "Location unknown", "categoryconstant": "PIDOME", "categoryname": "PiDome", "location": 1, "id": 1, "category": 2, "commandgroups": [ { "name": "Device values", "id": "values", "commands": [ { "commandtype": "data", "currentvalue": 15.39, "typedetails": { "visualtype": "", "graphtype": "time-series", "shortcut": 1, "datatype": "float", "prefix": "", "visual": false, "commandset": [], "id": "memusage", "label": "Memory usage", "deviceCommandValue": 15.39, "suffix": "MB", "graph": true } }, { "commandtype": "data", "currentvalue": 44.9, "typedetails": { "visualtype": "", "graphtype": "time-series", "datatype": "float", "prefix": "", "visual": false, "commandset": [], "id": "procheat", "label": "Pi temperature", "deviceCommandValue": 44.9, "suffix": "°C", "graph": true } }, { "commandtype": "data", "currentvalue": 5.16, "typedetails": { "visualtype": "", "graphtype": "time-series", "shortcut": 0, "datatype": "float", "prefix": "", "visual": false, "commandset": [], "id": "cpuusage", "label": "CPU load", "deviceCommandValue": 5.16, "suffix": "%", "graph": true } }, { "commandtype": "data", "currentvalue": 602.81, "typedetails": { "visualtype": "", "graphtype": "time-series", "datatype": "float", "prefix": "", "visual": false, "commandset": [], "id": "diskspace", "label": "Disk space", "deviceCommandValue": 602.81, "suffix": "MB", "graph": true } } ] } ] }, { "friendlyname": "PiDome User stats", "locationname": "Location unknown", "categoryconstant": "DISPLAY", "categoryname": "Display", "location": 1, "id": 17, "category": 11, "commandgroups": [ { "name": "Environment", "id": "0", "commands": [ { "commandtype": "data", "currentvalue": 16.0751, "typedetails": { "visualtype": "luxlevel", "graphtype": "time-log", "shortcut": 1, "datatype": "float", "prefix": "", "visual": true, "commandset": [], "id": "V_LIGHT_LEVEL", "label": "Light", "deviceCommandValue": 16.0751, "suffix": "Lux", "graph": true } }, { "commandtype": "data", "currentvalue": 22.3, "typedetails": { "visualtype": "celsiuslevel", "graphtype": "time-series", "shortcut": 0, "datatype": "float", "prefix": "", "visual": true, "commandset": [], "id": "V_TEMP", "label": "Temperature", "deviceCommandValue": 22.3, "suffix": "°C", "graph": true } } ] } ] }, { "friendlyname": "Motion sensor living", "locationname": "Location unknown", "categoryconstant": "MOTION", "categoryname": "Motion", "location": 1, "id": 20, "category": 10, "commandgroups": [ { "name": "Detection", "id": "devicereadings", "commands": [ { "commandtype": "data", "currentvalue": false, "typedetails": { "visualtype": "", "graphtype": "", "shortcut": 0, "datatype": "boolean", "prefix": "", "visual": false, "commandset": [], "id": "devicenoticed", "label": "Movement", "deviceCommandValue": false, "suffix": "", "graph": false } } ] } ] }, { "friendlyname": "Lights at wall cabinet", "locationname": "Location unknown", "categoryconstant": "LIGHT", "categoryname": "Lighting", "location": 1, "id": 24, "category": 3, "commandgroups": [ { "name": "Device actions", "id": "deviceactions", "commands": [ { "commandtype": "toggle", "currentvalue": true, "typedetails": { "shortcut": 0, "datatype": "hex", "commandset": { "off": { "label": "Off", "value": "off" }, "on": { "label": "On", "value": "on" } }, "id": "deviceswitch", "label": "Switch device", "deviceCommandValue": true } } ] } ] } ], "success": true, "message": "" } }
Which produces the blocks as seen in this screenshot (The upper part below the devices header):
Also, is it possible to assign custom id’s to the windows so i could create dynamic listings? Unless this already is possible.
Hi John,
We created an example based on yours and it runs fine with cookies enabled. The only part that is not included are the composeDeviceVisuals and setDeviceCatImage functions (the definitions of which we do not have). Do you receive any error messages when running this example? Please also make sure you are using the latest version of jQWidgets (3.5.0).
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="../../scripts/demos.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxwindow.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdatetimeinput.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcalendar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxtooltip.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxtabs.js"></script> <script type="text/javascript" src="../../jqwidgets/globalization/globalize.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdocking.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxpanel.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxsplitter.js"></script> <script type="text/javascript"> $(document).ready(function () { var data = { "jsonrpc": "2.0", "id": "DeviceService.getFavoriteDevices", "result": { "data": [ { "friendlyname": "Rasp server", "locationname": "Location unknown", "categoryconstant": "PIDOME", "categoryname": "PiDome", "location": 1, "id": 1, "category": 2, "commandgroups": [ { "name": "Device values", "id": "values", "commands": [ { "commandtype": "data", "currentvalue": 15.39, "typedetails": { "visualtype": "", "graphtype": "time-series", "shortcut": 1, "datatype": "float", "prefix": "", "visual": false, "commandset": [], "id": "memusage", "label": "Memory usage", "deviceCommandValue": 15.39, "suffix": "MB", "graph": true } }, { "commandtype": "data", "currentvalue": 44.9, "typedetails": { "visualtype": "", "graphtype": "time-series", "datatype": "float", "prefix": "", "visual": false, "commandset": [], "id": "procheat", "label": "Pi temperature", "deviceCommandValue": 44.9, "suffix": "°C", "graph": true } }, { "commandtype": "data", "currentvalue": 5.16, "typedetails": { "visualtype": "", "graphtype": "time-series", "shortcut": 0, "datatype": "float", "prefix": "", "visual": false, "commandset": [], "id": "cpuusage", "label": "CPU load", "deviceCommandValue": 5.16, "suffix": "%", "graph": true } }, { "commandtype": "data", "currentvalue": 602.81, "typedetails": { "visualtype": "", "graphtype": "time-series", "datatype": "float", "prefix": "", "visual": false, "commandset": [], "id": "diskspace", "label": "Disk space", "deviceCommandValue": 602.81, "suffix": "MB", "graph": true } } ] } ] }, { "friendlyname": "PiDome User stats", "locationname": "Location unknown", "categoryconstant": "DISPLAY", "categoryname": "Display", "location": 1, "id": 17, "category": 11, "commandgroups": [ { "name": "Environment", "id": "0", "commands": [ { "commandtype": "data", "currentvalue": 16.0751, "typedetails": { "visualtype": "luxlevel", "graphtype": "time-log", "shortcut": 1, "datatype": "float", "prefix": "", "visual": true, "commandset": [], "id": "V_LIGHT_LEVEL", "label": "Light", "deviceCommandValue": 16.0751, "suffix": "Lux", "graph": true } }, { "commandtype": "data", "currentvalue": 22.3, "typedetails": { "visualtype": "celsiuslevel", "graphtype": "time-series", "shortcut": 0, "datatype": "float", "prefix": "", "visual": true, "commandset": [], "id": "V_TEMP", "label": "Temperature", "deviceCommandValue": 22.3, "suffix": "°C", "graph": true } } ] } ] }, { "friendlyname": "Motion sensor living", "locationname": "Location unknown", "categoryconstant": "MOTION", "categoryname": "Motion", "location": 1, "id": 20, "category": 10, "commandgroups": [ { "name": "Detection", "id": "devicereadings", "commands": [ { "commandtype": "data", "currentvalue": false, "typedetails": { "visualtype": "", "graphtype": "", "shortcut": 0, "datatype": "boolean", "prefix": "", "visual": false, "commandset": [], "id": "devicenoticed", "label": "Movement", "deviceCommandValue": false, "suffix": "", "graph": false } } ] } ] }, { "friendlyname": "Lights at wall cabinet", "locationname": "Location unknown", "categoryconstant": "LIGHT", "categoryname": "Lighting", "location": 1, "id": 24, "category": 3, "commandgroups": [ { "name": "Device actions", "id": "deviceactions", "commands": [ { "commandtype": "toggle", "currentvalue": true, "typedetails": { "shortcut": 0, "datatype": "hex", "commandset": { "off": { "label": "Off", "value": "off" }, "on": { "label": "On", "value": "on" } }, "id": "deviceswitch", "label": "Switch device", "deviceCommandValue": true } } ] } ] } ], "success": true, "message": "" } }; var curBlock; for (var i = 0; i < data.result.data.length; i++) { var device = data.result.data[i]; curBlock = '#favoriteblock_' + i % 3; $(curBlock).append('<div class="favitemdock"><div><div onclick="refreshPageContent(\'/desktop/devices.html?deviceLink=' + device.id + '\')" style="cursor:pointer; line-height:17px;">' + device.friendlyname + '</div></div>\n\ <div>\n\ <div style="min-height:50px; padding-bottom:0px;">\n\ <img src="" id="fav_img_' + device.id + '" alt="' + device.friendlyname + '" style="float:left;"/>\n\ <table style="float:left;margin-left:5px;" id="fav_' + device.id + '"></table>\n\ <div style="clear:both;"></div>\n\ </div>\n\ </div></div>'); // composeDeviceVisuals('fav_' + device.id, device, false, true, true); // setDeviceCatImage('fav_img_' + device.id, device.categoryconstant); } $("#favoriteblock").jqxDocking({ cookieOptions: { expires: 3600 }, cookies: true, mode: 'docked', orientation: 'horizontal', width: 820 }); $("#favoriteblock").jqxDocking('hideAllCloseButtons'); $('#favoriteblock').jqxDocking('showAllCollapseButtons'); }); </script> </head> <body class='default'> <div id="favoriteblock" style="max-height: 500px; margin-left: 0px; overflow-x: hidden; overflow-y: auto;"> <div id="favoriteblock_0"> </div> <div id="favoriteblock_1"> </div> <div id="favoriteblock_2"> </div> </div> </body> </html>
As for assigning ids to the windows, this is possible and is done in the demo Default Functionality.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
I will try the above and will report back, thank you.
John.
Hi Dimitar,
I think i have found the issue. My docking is loaded not in the head but in the body after a async call to the getFavoriteDevices. This function is dynamic in the way that users can add/remove their favorite devices which will cause this rpc call to have a entry added or removed.
I have tested it with 3.5.0 and it now works only when i use custom device id’s on the windows, which is logical due to the application setup, so it is clear to me now. When i add a new favorite device (new block). All goes fine the moved blocks are put where they are supposed to and the other blocks are shifted according the rpc call output order. So that’s good!
But, here it comes, when i remove a device, so a specific window id is not present, i get the popup again about an invalid json. This is a kinda misleading message because the json itself is not invalid, the json is correct, but the docking just can not find the window id stated in the json.
So yes, it is working, but, i really really really need to get rid of this alert box in a graceful way so it just skips the not found window id and it continues with the the window following up.
If i have to hack and slash my way through the code i won’t mind. This dashboard setup has been presented during JavaOne this week. So when i release an upcoming version i really need to get this up and running without errors. So if there is any option to discard a non found id you will make me very happy. If there ain’t such an option could you please point me to the location where i can suppress this message and let the docking continue it’s work?
Hi John,
Please contact us by e-mail at support@jqwidgets.com where we can discuss the matter further.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.