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

115
Views
Actualizar variable de contexto con ajax

obteniendo nulo en lugar del valor actualizado cuando el evento se activa en la plantilla, obteniendo el valor correcto en el terminal, por ejemplo success 6 . ¿Cómo obtengo el valor real para representar en lugar de nulo? Siéntase libre de mejorar esta pregunta si ve algo incorrecto. ¡Alegría!

Busqué mucho en la comunidad e intenté muchas cosas, pero no pude encontrar la causa del problema. ¡Espero que alguien pueda ayudarme!

repositorio reproducible: https://github.com/bettstogain/reproducible_shop/tree/main/env

Este es mi código:

 path('ajax_update/', views.ajax_update, name="ajax_update"),

vista

 #bagstuff is a function that sees if the user is authenticated and does get_or_create #or is not authenticated and refers to use the cookie def ajax_update(request): stuff = bagstuff(request) bag = stuff['bag'] # if_ajax returns, request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest' if is_ajax and request.method == "GET": #trying to get the bag value after the event is triggered if bag: print("success", bag) #trying to get the bag and put it in JsonResponse data_attribute = request.GET.get(bag) #print(data_attribute) -- this prints null return JsonResponse(data_attribute, safe=False, status=200) else: print("failed") context = {"bag": bag}

modelo:

 <script> var update_bag_url = "{% url 'store:ajax_update' %}"; </script>

JavaScript:

 function update_bag() { // optional: don't cache ajax to force the content to be fresh $.ajaxSetup ({ cache: false }); // specify loading spinner var spinner = "<img alt='loading..' />"; $("#lil-icon-two").html(spinner).load(update_bag_url); }
over 4 years ago · Santiago Trujillo
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!