The Lua script is invoked in the HTM via XHR, LUA scripts location:/usr/lib/lua/luci/controller/admin/xxx.lua xxx.htm: 1. Static Call
var callpath= ' <%=luci.dispatcher.build_url ("admin", "xxx", "dev_info")%> ';
callpath=callpath+ '/' +param1+ '/' +param2; If you need to pass a parameter
Xhr.get (Callpath,null,function (x,rval) {
......
}
);
2. Dynamic Invocation
var callpath= ' <%=luci.dispatcher.build_url ("admin", "xxx", "dev_info", parameter)%> ';
Xhr.poll (5,callpath, null,function (X,callpath rval) {...
}
);
The first parameter is a timed refresh time (in S)
The second parameter is the path generated by the Luci, where parameter is the parameter passed to LUA
The third parameter is temporarily unknown, and filling null does not affect
The fourth one is the callback function:
X: Is a XHR object, generally not
Rval: Is the return value of the LUA function (general value rval[0])
3. Trigger Submit Commit Call
<script>
document.getElementById ("Id_input_submit"). Value=paramt; Value will be uploaded to Lua.
document.getElementById ("Id_input_submit"). Click (); Triggering the Submit event
</script>
<form style= "Display:none" method= "post" action= "<%=luci.dispatcher.build_url (" admin "," xxx "," dev_info ")% > "enctype=" Multipart/form-data ">
<input id= "Id_input_submit" name= "Getpackage" type= "Submit" \>
</form>
Xxx.lua:
Entry ({"admin", "xxx", "Dev_info"}, Call ("Dev_info"), nil). Leaf = True
page methods are identical:
--paramval: Receives the passed down parameter, (has two, writes two to enter the parameter)
function Dev_info (paramval)
Local function Getdev (val)
......
Return .....
End
Luci.http.prepare_content ("Application/json")
Luci.http.write (' [')
Luci.http.write_json (Getdev (Paramval))
Luci.http.write ('] ')
End
Page Method 3:
function Dev_info ()
Local Value=luci.http.formvalue ("Getpackage")--Gets the value of the passed value, where Getpackage is the name of input
.......
End