Home > other >  Ajax luci web front end data interaction
Ajax luci web front end data interaction

Time:10-04

: the jquery - 1.3.2. Min./js in luci - static/resources/directory

1. New view
/usr/lib/lua/luci/view/test directory new setHostname. HTM file

& lt; ! DOCTYPE html>
& lt; html>
& lt; head>
& lt; Meta charset="utf-8" & gt;
& lt; title> The SET - HOSTNAME
& lt; The script type="text/javascript" SRC="https://bbs.csdn.net/luci-static/resources/jquery-1.3.2.min.js" & gt; & lt;/script>
& lt;/head>
& lt; The script type="text/javascript" & gt;
The function the login () {
Var name=$(' # txt1). Val ();
//alert (name);

$. Ajax ({
Url: the hostname,
DataType: 'json,
Method: "post",
Data: {the hostname: name},
Success: the function (r) {
Alert (r.d ata);
Alert (r.m sg);
},
Error: function (XMLHttpRequest, textStatus errorThrown) {
Alert (XMLHttpRequest. Status);
Alert (XMLHttpRequest. ReadyState);
Alert (textStatus);
}
});
}
$(function () {
Alert (" ok ");
});
& lt;/script>
& lt; body>
& lt; p> Setting the IP address


& lt; The form method="get" action="& lt; %=luci. Dispatcher. Build_url (" admin ", "test", "hostname") % & gt;">
& lt; Input type="text" id="txt1" name="hostname" & gt;
& lt; The button id="submit" & gt; . & lt;/button>
& lt;/form>
& lt; Input style="width: 80 px" type="button" value="https://bbs.csdn.net/topics/dpost" onclick="login ()"/& gt;
& lt;/body>
& lt;/html>
2. New controller
The/usr/lib/lua/luci/controller/admin directory test. The new lua

Module (luci. Controller. Admin. "test", package. Seeall)

The function index ()
Entry ({" admin ", "test"}, alias (" admin ", "test", "test"), and _ (" Test1 "), 30). The index=true
Entry ({" admin ", "test", "control"}, cbi (" admin_test/control "), and _ (" ControlTest "), 1)
Entry ({" admin ", "test", "hello"}, the template (" test/hello "), and _ (" HelloTest "), 2). The dependent=false
Entry ({" admin ", "test", "test - the cbi"}, cbi (" admin_test/test - the cbi "), and _ (" test - the cbi "), 3). The dependent=false
Entry ({" admin ", "test", "mytest"}, the template (" test/setHostname "), and _ (" mytest "), 4). The dependent=false
Entry ({" admin ", "test", "hostname"}, call (" set_hostname "))
End


The function set_hostname ()
The local hostname=luci. HTTP. Formvalue (" hostname ")
Local executeString="uci set test. @ controlboard [0]. The hostname="). The hostname
Luci. Sys. Exec (executeString)
Luci. Sys. Exec (" uci commit test ");
The local o={}
O [' data ']="ok"
O [' MSG ']='success'
Luci. HTTP. Prepare_content (" application/json ")
Luci. HTTP. Write_json (o)
End
3. Verify
/etc/config/directory of the test file hostname attribute the default display OpenWrt

Enter the page of mytest


Text box input cbox and click on "dpost" button to submit the


View/etc/config/test files in the directory of the hostname property changes as the cbox

  • Related