Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to build a web app on asp.net core. Here’s what I want to able to do:
where a user can login and click a timer to start.
Even when the user logs of the timer still keeps track of time in real time until someone (the user/ administrator) logs back in to click the end button.
Then I want to be able to capture the start time and end time (in real time) so that I can calculate the difference and store it.
I know I’m probably going to need some Javascript code to have the timer run in the browser but I’m not sure how to keep the timer running even when the user logs off. Any suggestions on how to achieve this?
When user clicks button you send request to the server and save time of the click into the database.
When user opens page, you get start time from the DB and start counting from it.
When user clicks stop button, you send request to the server and save the etop time.
Of course you have to use it's own id for each timer.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I need to check the database if a new row is created for the user and show him a popup message. I should do it for every user, and it should happen without refreshing the page (Live). Shall I try pusher/socket or make Ajax call every 5 seconds? I really want to use Ajax because it's easier and straightforward.
The related table has nearly 50,000 rows, and I'll need to check if a new row with the particular user_id is added through a postback.
Since the information needs to be transmitted from the server (at some unknown time) to the client, it would be far more elegant to use a WebSocket (JS docs). This way, instead of the client having to repeatedly ping the server, the client just has to establish a socket connection once, and the server can send the data whenever it's ready.
you can try setInterval function in JS for call Ajax function.
function checkAjaxFunc() { ... }
setInterval(function() {checkAjaxFunc()},5000);
Why not a scheduled task?
See here
You could set a cache value every five second and in ajax call read only this value. in this way you will not read DB and only a cache value every 5 seconds instead of once every 5 seconds for each user logged in
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm building pretty simple appointment system with node js, js and sql.
im getting the data: name, hour, day -> store it in sql (sending sms to the client) and edit the day and hour in the sql so it will not show it on the website.
everything is working well.
now i want that when some user made appointment it will show to other users that this hour in this day is not available (right now it is happening but the other users should refresh the page to see the update).
i think socket io can help me here.
i read all the documentation and its all about chat rooms.. before i get my hands dirty with socket io and trying to modify it, i want to ask for help . do you think it is possible to do it? and if yes what is the best way for your opinion.
thanks in advance
Yes. You definitely can use WebSocket API (or any library built on top of it, e.g. Socket.io) to update a client's webpage without it having to refresh the page.
You could simply emit an event from your NodeJS application on receiving an an appointment request and handle the event's payload at the client's end to update the webpage.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am using express,react and mysql. I want to create like/dislike system for the comments. I googled it and most people recommended to disable the button after single click. But I don't want that. Even the user refreshes the tab or access his profile from another device. When he sees that comment again, he should see that he already liked that comment and he should not be able to like it again. I am thinking of storing all the likes and dislikes in the mysql database for each user. Does it decreases the number of queries to database and affect the performance? What is the proper solution?
If you want to show the users who liked/disliked a post (or a comment), you will have to insert a new row along with the user-id for each like/dislike. And regarding the multiple-likes problem, you will have to check whether or not there is a row with the same user-id and comment-ids as the ones you are getting from the post request, if so, just ignore the request and tell the user something like "cannot like more than once", otherwise insert a new row.
Another thing to consider is, what do you plan to do in cases where a user likes a comment and immediately unlikes it ? If you are sending real-time notifications, then the target will get a false notification (that is, if you don't tackle this problem). That was something I hadn't considered and there simply was no way (but i am sure there is a trick).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
1) What happens in the background when a webpage is closed?
2) How can I make the webserver think the page is still being viewed so my script may run?
I would post some code but I don't know where to start, looking for some terms and suggested methods to pursue, not necessarily code examples.
Example:
Let's say I have a javascript that needs to run for a certain amount of time once the user visits the page, but the user closes the page before it completes.
How can I (fake) the connection as being alive (even though the user left) until the script completes?
What happens in the background when a webpage is closed?
unload event is triggered and handled, script execution gets stopped, all webworkers get killed, everything gets cleaned up from memory, etc.
How can I make the webserver think the page is still being viewed so my script may run?
What however is possible to start an ajax request in your page which doesn't get killed by the server when the client aborts the request. In php for example you should take a look for that at ignore_user_abort().
You could try to warn user before leaving the page, and tell him that some work still needs to be done - but nothing more than that, the user will still be able to close the window/tab and your script will abort.
To warn the user, try this:
window.onbeforeunload = function() {
return 'Just give me a minute, please';
};
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I can't explain what I want to do in the correct terminology but I'll give an example.
A website has on most pages a 'quick contact' form in a sidebar. Once the form is submitted on any given page that contains it, it fades and a confirmation message appears. How can I allow the website to identify that the form has already been submitted and then just display the confirmation message on all areas which would have contained it (throughout the whole site). Ideally, this would only occur for a limited period of set time (such as after 1 day or close of browser it resets and the form is present when that specific user access' the website again.
Honestly, I have no idea where to even start with this, but an important thing to note is that the form submission is just a 'dummy submission' and is not actually sending any data to the server (I know this is wrong but this task has the specific requirement of predominately client side access).
Edit: A cookie was what I was after.
You have several options to store flags in the client-side, like cookies and local storage to name a few. If this functionality is bound to a user account, you can also set a flag in the DB table or column that's related to that user.