Hi
following is my current code, Using B4j to refresh browser side page data every fixed timimg with websocket.
My new application is, How could i refresh page with ajax/get to B4J in fixed timing from browser, I don't use websocket ?
B4J
B4X:
Sub timer2_tick
dim data As Map
data.Initialize
data.Put("resultc",plc.resultc) ' 結果顏色
data.Put("resultn",plc.resultn) ' 結果數值
'
ws.RunFunction("refresh_page",Array As Object(data))
ws.Flush
End Sub
Browser
B4X:
function refresh_page(io)
{
graphic.setValue('resultc',io.resultc);
graphic.setValue('resultn',io.resultn);
};
You don't use websockets for regular GET requests. You can add an additional non-websocket handler or better raise an event from the browser instead of sending a GET request.
I will use Handle to recive browser request. And then respone a map to browser. How to coding like followig io variable ? and then i can use then like io.resulttc,,, in the html file.
browser
B4X:
function refresh_page(io)
{
graphic.setValue('resultc',io.resultc);
graphic.setValue('resultn',io.resultn);
};