change Dom element based on firebase admin value events

前端 未结 2 931
鱼传尺愫
鱼传尺愫 2021-01-28 03:37

I have a simple HTML page printed out inside a Servlet. Here I have setup firebase admin sdk and have set a value event listener for a path.

When the events fire, I wish

相关标签:
2条回答
  • 2021-01-28 04:03

    With servlets, your clients won't see any page updates until they send a new request to your application server. What you can do is get your ValueEventListener to update the state of an in-memory object. Then your servlet can read the latest state of that object whenever constructing the HTML output.

    0 讨论(0)
  • 2021-01-28 04:10

    So i managed to solve this using a JSP instead of a Servelet.

    In either case, the solution was to tranfer all the logic to a JavaScript function. Then calling the said function on body load.

    onload=callthefunction()
    

    The firebase listeners were converted from java to the JavaScript version:

    on()
    off()
    

    This way there is need to call ajax or anything and the elements that need to be changed can be directly altered from JavaScript

    0 讨论(0)
提交回复
热议问题