Hello, i am trying to switch the band using ajax query from GUI web page wifi_overview.htm. i also want to add one parameter to set "scanband" as per below in configuration file [etc/config/wireless]
ajax code:
<script type="text/javascript">//<![CDATA[
function switchTo2G()
{
disableSwitch(true);
var http = new XMLHttpRequest();
var url = "<%=luci.dispatcher.build_url("admin/network/wireless/wifi0.network1")%>";
var params = "cbi.submit=1&tab.wireless.wifi0=general&cbid.wireless.wifi0.channel=auto&cbid.wireless.wifi0.txpower=16&cbid.wireless.wifi0.hwmode=11ng&cbid.wireless.wifi0.htmode=HT20&tab.wireless.cfg033579=general&cbi.cbe.wireless.cfg033579.doth=1&cbi.cbe.wireless.cfg033579.uapsd=1&cbi.cbe.wireless.cfg033579.wmm=1&cbid.wireless.cfg033579.ssid=CD-2.4G&cbid.wireless.cfg033579.mode=ap&cbid.wireless.cfg033579.network=lan&cbi.cbe.wireless.cfg033579.hidden=1&cbid.wireless.cfg033579.encryption=psk2&cbid.wireless.cfg033579.cipher=auto&cbid.wireless.cfg033579._wpa_key=CD-2.4GHz&cbi.apply=Save+%26+Apply";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
restartServ();
}
}
http.send(params);
}
function switchTo5G()
{
disableSwitch(true);
var http = new XMLHttpRequest();
var url = "<%=luci.dispatcher.build_url("admin/network/wireless/wifi0.network1")%>";
var params = "cbi.submit=1&tab.wireless.wifi0=general&cbid.wireless.wifi0.channel=36&cbid.wireless.wifi0.txpower=16&cbid.wireless.wifi0.hwmode=11na&cbid.wireless.wifi0.htmode=HT20&tab.wireless.cfg033579=general&cbi.cbe.wireless.cfg033579.doth=1&cbi.cbe.wireless.cfg033579.isolate=1&cbi.cbe.wireless.cfg033579.uapsd=1&cbi.cbe.wireless.cfg033579.wmm=1&cbid.wireless.cfg033579.ssid=CD-5G&cbid.wireless.cfg033579.mode=ap&cbid.wireless.cfg033579.network=lan&cbi.cbe.wireless.cfg033579.hidden=1&cbid.wireless.cfg033579.encryption=psk2&cbid.wireless.cfg033579.cipher=auto&cbid.wireless.cfg033579._wpa_key=CD-2.4GHz&cbi.apply=Save+%26+Apply";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
restartServ();
}
}
http.send(params);
}
function restartServ()
{
var apply_xhr = new XHR();
apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "restart", "wireless,network,firewall")%>', null,
function() {
var checkfinish = function() {
apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "status")%>', null,
function(x) {//alert(x.responseText);
setTimeout('disableSwitch(false)', 10*1000);
}
);
}
window.setTimeout(checkfinish, 1000);
}
);
}
function disableSwitch(status)
{
document.getElementById('switch2G').disabled = status;
document.getElementById('switch5G').disabled = status;
}
//]]></script>
The config file: etc/config/wireless
config wifi-device 'wifi0'
option type 'qcawifi'
option macaddr '00:26:75:bd:37:24'
option txpower '16'
option htmode 'HT20'
option disabled '0'
option channel '36'
option hwmode '11na'
config wifi-iface
option device 'wifi0'
option mode 'ap'
option network 'lan'
option encryption 'psk2'
option key 'CD-2.4GHz'
option scanband '1'
option ssid 'CD-5G'