Reputation: 230028
Play's flash is a "temporary storage mechanism that is kept for the duration of the next request", using cookies.
Is it possible to read the flash from javascript?
I want to implement a generic client-side notification mechanism, and also access that mechanism from the server. What I imagine is for any controller to do:
flash.put("notification", "You have been notified");
And then for my main.js
to check if the "notification" flash exists, and if it does display it above (similar to Stack Overflow's notification mechanism).
However, I suspect that flash might be encrypted in a way that the client side cannot read it. I haven't found any code samples that show how to read it from the client side JS (not in a template). Is this possible directly?
As I'm writing this question, I'm actually coming up with a way to implement this: I can put a hidden div in the main template that all my views extend, and access that div from JS. Does it make sense? Is there a simpler approach?
Upvotes: 1
Views: 739
Reputation: 3833
For me you have two solutions
Upvotes: 0
Reputation: 14373
I don't think it's possible to use JavaScript to read flash, even via the cookie. That cookie is actually encrypted with a security seeds (application.secret) configured in your application.conf.
However it is possible to implement what you want.
Upvotes: 1