Hello,
I'm trying to call a function in my controller from one of my views by using the XHR.poll method, and have the call return some uci data from my /etc/config/ configuration file. However, I'm not successful, and can't really figure out what's going on.
Right now, the javascript in my view code looks like this:
function myFunction() {
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "package", "call")%>/', null, function(x, data) {
alert("Data is " + data);
});
};
My controller call looks like this:
function action_my_function()
local uci = luci.model.uci.cursor()
luci.http.prepare_content("text/plain")
luci.http.write(uci:get("package", "section", "option"))
end
Also, here is my entry code, but I don't think the problem lies here at all:
entry({"admin", "package", "call"}, call("action_my_function"), nil).leaf = true
I can see that the luci.http.write returns what I like (that is, the correct configuration option value in my configuration file) by navigating to "http://NODE/cgi-bin/luci/admin/package/call" in my browser, however, on the actual view page, if I set a breakpoint in my javascript code, Firebug tells me that my "data" variable is null.
I'm sure I'm doing something simple completely wrong, but I can't figure out what. Does anyone have any clue? Is there a more elegant way of doing what I want instead of using luci.http.write? Like, can I just use a 'return' in the controller Lua code? I've tried this method before, but to no avail.
As always, thanks in advance for any insight.
--
Justyn