8
I’m wearing the event beforeunload
to try to send an ajax request to the server before the user leaves the page but it has not worked out very well..
Is there any way to send a request that continues to be executed on the server even if the browser window is closed? Maybe with socket, Curl?
Reason: I am making a survey form and would like satisfaction that if the user closes the window and does not complete the search, save what has been answered so far
Who gave the downvote could please leave written the reason?
– Silvio Andorinha
With socket, I don’t think so. But I think it’s possible to make an AJAX request if you synchronise it. But I don’t think it’s a good idea...
– Artur Trapp
Do you have how to better detail your purpose? What would this request be and what is the purpose of it? Have you tried to create a thread on the server to process whatever it takes?
– Woss
@Andersoncarloswoss yes, I edited the question
– Silvio Andorinha
@Silvioandorinha think that in this given situation, the best alternative is to save periodically what has already been filled. We have a similar system here at the company and it saves what has already been filled minute by minute
– Artur Trapp
This is unreliable. The user can "close" the tab by closing the process, hence your code will not run.
– Oralista de Sistemas
@Arturotemplário is.. it seems that at the moment this is the best solution, but it would be great if there was something so that we could leave running in the background in the browser even with the tab closed
– Silvio Andorinha
@Silvioandorinha try to use the Ratchet, then whenever the user answers any question, send the answer by it.
– Tobias Mesquita
@Silvioandorinha take a look here (http://stackoverflow.com/questions/4945932/window-onbeforeunload-ajax-request-in-chrome), have a few solutions with
onbeforeunload
. But as @Renan said, if the tab closes in other ways, it won’t fall there– Artur Trapp
Doubt why you don’t start saving each user response after they leave the field there even if they close the window or happen any unexpected event you already have your result saved.
– Gustavo Castro