X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci2%2Fui.git;a=blobdiff_plain;f=luci2%2Fhtdocs%2Fluci2%2Fluci2.js;h=4e872188d0082c52a1b128273e10888e0066a593;hp=6c7db677418081ed9582c9fcf8da1835dd56d3af;hb=dd7878e8d48e2a3606a97265b9b83ac0d80cda72;hpb=5e77a7735b0594f50b5ce6e4f3d2b2cb6bf5d546 diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index 6c7db67..4e87218 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -505,43 +505,48 @@ function LuCI2() data: JSON.stringify(req), dataType: 'json', type: 'POST', - timeout: _luci2.globals.timeout - }).then(cb); + timeout: _luci2.globals.timeout, + _rpc_req: req + }).then(cb, cb); }, _list_cb: function(msg) { + var list = msg.result; + /* verify message frame */ - if (typeof(msg) != 'object' || msg.jsonrpc != '2.0' || !msg.id) - throw 'Invalid JSON response'; + if (typeof(msg) != 'object' || msg.jsonrpc != '2.0' || !msg.id || !$.isArray(list)) + list = [ ]; - return msg.result; + return $.Deferred().resolveWith(this, [ list ]); }, _call_cb: function(msg) { var data = [ ]; var type = Object.prototype.toString; + var reqs = this._rpc_req; - if (!$.isArray(msg)) + if (!$.isArray(reqs)) + { msg = [ msg ]; + reqs = [ reqs ]; + } for (var i = 0; i < msg.length; i++) { - /* verify message frame */ - if (typeof(msg[i]) != 'object' || msg[i].jsonrpc != '2.0' || !msg[i].id) - throw 'Invalid JSON response'; - /* fetch related request info */ - var req = _luci2.rpc._requests[msg[i].id]; + var req = _luci2.rpc._requests[reqs[i].id]; if (typeof(req) != 'object') throw 'No related request for JSON response'; /* fetch response attribute and verify returned type */ var ret = undefined; - if ($.isArray(msg[i].result) && msg[i].result[0] == 0) - ret = (msg[i].result.length > 1) ? msg[i].result[1] : msg[i].result[0]; + /* verify message frame */ + if (typeof(msg[i]) == 'object' && msg[i].jsonrpc == '2.0') + if ($.isArray(msg[i].result) && msg[i].result[0] == 0) + ret = (msg[i].result.length > 1) ? msg[i].result[1] : msg[i].result[0]; if (req.expect) { @@ -572,10 +577,10 @@ function LuCI2() data = ret; /* delete request object */ - delete _luci2.rpc._requests[msg[i].id]; + delete _luci2.rpc._requests[reqs[i].id]; } - return data; + return $.Deferred().resolveWith(this, [ data ]); }, list: function()