duanjingwei7239 2016-09-13 08:45
浏览 146


I have created a web site that allows for the submission of HTML forms with multiple stages of form authorisation. For example a Employee Submits a Leave Application which is then Authorised by a Supervisor. Multiple users may have the permission to authorise a form at any particular stage.

The issue i have run into is only 1 user should be able to edit the form at any stage.

My idea was on page load set a IsLocked column in the database to true when the page loads and i can use this to see if anyone else has it locked. I would then set it back to 0 when the person leaves the page. A person can leave the page by modifying the form and clicking submit or just by navigating away.

I can easily lock the page or check if its locked using the document.ready function and a ajax request or doing it straight in PHP however i am stuck in finding a way to remove the lock when the page gets redirected.

I have looked into the following methods:

  1. http://www.bennadel.com/blog/1520-binding-events-to-non-dom-objects-with-jquery.htm (Using a custom function which constantly checks to see if the href has changed. I can't seem to get this function to work in Chrome, Firefox, IE)
  2. https://developer.mozilla.org/en-US/docs/Web/Events/popstate (The problem us it only called when the forward or back buttons in web browser are used)

Question: How can l reliably get when a user has left the page? Is there a better way to handle the form locking mechanism?

  • 写回答

2条回答 默认 最新

  • douhuan4699 2016-09-13 09:01

    I would recommend WebSockets. They provide real-time communication between connected clients to a server. This could solve your problem by broadcasting a message to all user's about which forms are locked.

    You have a few options for the websocker server, a popular one being NodeJs. Take a look at this answer for the various libraries available.

    Once your server is running, each client could broadcast a message to the other clients with the form that needs to be locked:

    // Send text to all users through the server
    function sendText() {
      // Construct a msg object containing the data the server needs to process the message from the client.
      var msg = {
        type: "message",
        text: document.getElementById("myLockedForm").id,
        id:   clientID,
        date: Date.now()
      // Send the msg object as a JSON-formatted string.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 关于cpci总线的几个问题,有点迷糊
  • ¥15 乳腺癌数据集 相关矩阵 特征选择
  • ¥15 我的游戏账号被盗取,请问我该怎么做
  • ¥15 通关usb3.0.push文件,导致usb频繁断连
  • ¥15 有没有能解决微信公众号,只能实时拍照,没有选择相册上传功能,我不懂任何技术,,有没有给我发个软件就能搞定的方法
  • ¥15 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造
  • ¥15 springboot国际化
  • ¥15 搭建QEMU环境运行OP-TEE出现错误
  • ¥15 Minifilter文件保护