Here's the situation:
I have a web application, a response to a request for a list of resources, say:
/items
Initially, the request is requested directly by the web browser, moving along this path. The browser uses the standard "Accept" header, which includes "text / html", and my application notices this and returns the HTML content for the list of elements.
The returned HTML has some JavaScript (jQuery) that then executes an ajax request to retrieve the actual data:
/items
Only this time, the Accept header is explicitly set to application / json. Again, my application notices this, and JSON returns correctly to the request, the data is inserted into the page, and everyone is happy.
The problem comes . The user goes to another page and then presses the BACK button. They are then prompted to save the file. This, as it turned out, is the JSON data of the item list.
So far, I have confirmed that this will happen in both Google Chrome and Firefox 3.5.
There are two possible types of answers:
How can I fix the problem. Is there some kind of magic combination of Caching Headers or other voodoo that make the browser do the right thing here?
If you think I'm doing something terribly wrong here, how do I go about it? I am looking for correctness, but also trying not to sacrifice flexibility.
If this helps, the application is a JAX-RS web application using Restlet 2.0m4. I can provide sample request / response headers if this is useful, but I find the problem fully reproducible.
json ajax web-applications jax-rs content-negotiation
Mark renouf
source share