oob例程里有ajax的js类,使用这个可以很方便的刷新呀:)
使用方式也很很方便:
$(document).ready(function(){
updateLedStatus();
$("button_led1_on").click(function{
setLed('1', 'on');
});
$("button_led1_off").click(function{
setLed('1', 'off');
});
........
});
function updateLedStatus(){
updatePoll = new com.TI.tokenPoller({
"paramPage": "param_led.html",
"refreshRate": 1 * 1000, // every second
"valueMap": [{
"paramId": "led1_state",
"outputSuccess": function(output) {
$('#light1').html("状态:" + output);
},
"outputDefault": function() {
$('#light1').html("重新载入");
}
},
{
"paramId": "led2_state",
"outputSuccess": function(output) {
$('#light2').html("状态:" + output);
},
"outputDefault": function() {
$('#light2').html("重新载入");
}
},
{
"paramId": "led3_state",
"outputSuccess": function(output) {
$('#light3').html("状态:" + output);
},
"outputDefault": function() {
$('#light3').html("重新载入");
}
}]
});
}
function toggleSwitch(led, status){
var lightSwitch = "#lightSwitch" + led;
if (status == "on") {
$(lightSwitch).attr("backgroundPosition", "0 0");
} else {
$(lightSwitch).attr("backgroundPosition", "0 -72px");
}
}
function setLed(led, status) {
if((led == "1" || led == "2" || led == "3") &&
(status == "on" || status == "off")){
var params = "LED" + led;
if(status == "on")
params += "_ON";
else
params += "_OFF"
$.post("No_content", {"__SL_P_ULD" : params});
toggleSwitch(led, status);
}
}
请求的参数param_led.html文件:
__SL_G_UL1
__SL_G_UL2
__SL_G_UL3