0

How do I make this permanent and global?
By this I mean the color change of the div!
The data has been stored to DB and the div must remain red for all times for all computers ha-ha and not until the page reloads! How can this be achieved?

        var x = document.getElementById("mySelect1").selectedIndex;
        var y = document.getElementById("mySelect2").selectedIndex;
        var color = "#ff0000";
        request.done(function (data) {
            if (data != -1) {
                if (x==0 && y==0) {
                    document.getElementById("A9").style.backgroundColor = color;
                }
                alert("You Have successfully made an appointment");
                location.assign("AjanvarausPage.html");
            }
undefined
  • 1,019
  • 12
  • 24
MicroDev92
  • 169
  • 1
  • 15
  • You have to use some sort of server side code. Also if you want it to apply the effect to all computers, i think you should look into something like SignalR to push information to all users on your site. – Carsten Løvbo Andersen Feb 20 '17 at 18:41
  • well I'm already using MVC and asp.net for the server side is it achievable through some HttpGet or Post methods? What is SignalR? @CarstenLøvboAndersen – MicroDev92 Feb 20 '17 at 18:45
  • You need to run a check for newly made appointments say every 10sec. Make a ajax request to get list of appointments done in last 20sec(assuming list check is done every 10 sec, 20 sec would be safe as sometimes there maybe lags). Now loop through this list of newly made appoints and make them red. – Zeus Feb 20 '17 at 18:48
  • @Zeus this will maybe keep the circle red, even if I don't know how to type the Ajax to check for the list of appointments. but how do I make it global? – MicroDev92 Feb 20 '17 at 18:50

1 Answers1

1

Server-side code will be needed to keep track of the change and notify all clients. The former will require some form of persistence, global memory/cache or database perhaps, while the latter is the trickier part. Since a server generally doesn't know if a web client is connected or not it has to be told there is a client needing to be notified.

But there are a number of ways this could be done.

Polling

Each client must poll the server-side code for potential changes. There are in general two different types of polling, short and long.

Short Polling

each client will need to ask the server if there are changes in a loop, usually with a delay to prevent hammering the server. The server responds immediately notifying the client if there are changes or not.

Long Polling

similar to short polling, with the single exception of the server not responding unless there are changes. This keeps the request open until it is either satisfied (there are changes to report) or it times out.

Push Notification

There are technologies, such as SignalR, that has the client register with the server and can then be notified repeatedly without further notification.

David Culp
  • 5,354
  • 3
  • 24
  • 32
  • are there any tutorials that can help me learn the implementation of polling? is it diffcult? Which implementation is faster? SignalR or Polling? How do I implement it into my code? Is it possible to create that persistence through Get/Post Api methods? how? Sorry for the aggressiveness of questions? but I know nothing of polling and SignalR :/ – MicroDev92 Feb 20 '17 at 19:24
  • here is a question with answers that get around to answering most (if not all) of your questions about polling. http://stackoverflow.com/questions/1086380/how-does-facebook-gmail-send-the-real-time-notification – David Culp Feb 20 '17 at 19:31
  • SignalR is a library of its own and is based here. https://www.asp.net/signalr – David Culp Feb 20 '17 at 19:32
  • as for the question of persistence, once the request is on the server, you have anything that can be done in C# at your disposal. Where you decide to persist the data, and how long to keep it, will depend entirely on the needs of your application. The same can be said of which one is faster -- it depends on the needs of the application. – David Culp Feb 20 '17 at 19:36