Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
averiguar cuándo el usuario abandona una página en django

Tengo una función ajax que envía solicitudes a una vista de Django cada segundo:

 function get_updates() { $.ajax({ url: full_path, type: 'GET', data: {latest_pk: latest_pk}, success: function(json) { ... }, complete: function(data) { setTimeout(get_updates, 1000); } }); } get_updates();

obtener el método de la vista es así:

 def get(self, request, *args, **kwargs): if request.GET: # If there are GET parameters, use them to return updates. response = self.get_updates(request.GET.get("latest_pk")) return JsonResponse(response) else: # Otherwise if the url is simply requested, # return the rendered chat page. return super().get(request, *args, **kwargs)

¿Cómo puedo ejecutar algún código en Django, después de que las solicitudes dejaron de enviarse? Necesito guardar la hora de la última solicitud.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Pruebe esto en javascript, hay un evento llamado ."beforeunload" .
Esto es solo una idea de cómo puedes lograrlo.

 <script> window.addEventListener("beforeunload",function(){ $.ajax({ url: full_path, type: 'GET', data: {latest_pk: latest_pk}, success: function(json) { // add your other logic here } }); }); </script>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!