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?