• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

@ControllerAdvice session data and ajax issue

Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using @ControllerAdvice to use shared data accross my application.

It all worked fine until I did an ajax request.

The problem is that the relevant data from @ControllerAdvice is always a step behind.

This is the relevant code from @ControllerAdvice

And my view:

Now, If I use the application normally without ajax, meaning if let's say I add an item to the cart and the page refreshes normally, then it all works as expected, I get the correct values for csize and ctotal, however if I use ajax to hit the appropriate url and then return the view, the csize and ctotal variables are always a step behind, so for example if there are no items added and I add the first item, I don't see a difference via ajax, and then if I add another then the value of csize is 1 (instead of 2), then if I add another it is 2 instead of 3 and so on. But if I refresh the page it is correct.

So basically via ajax the data from @ControllerAdvice is a step behind, any idea why? I mean I basically get "why", because I guess only an html view is returned and there is no real redirect, but can I still achieve proper values somehow?
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
Enterprise-grade Excel API for Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!