views:

84

answers:

2

Hi,

I have an AJAX controller action which returns JSON. The returned JSON is handled via jQuery and contains a message displayed in an update div. The JSON also contains a flag which indicates a change in state. If this is true the entire page needs to be reloaded from a different url. This is currently performed in the jQuery using window.location.replace(url).

In the situation where a full page refresh occurs, I still want to display the message from the JSON in the update div, but after the page has fully reloaded.

How can I ensure the div is updated with the message after the window.location.replace call and the page has been completely reloaded?

Thanks.

(I realise AJAX is not intended for full page refreshes but I can't think of a simple way of avoiding it in this scenario. Normal behaviour here is updating the div with a status message.)

A: 

Add a query string to the url that tells page to show the box e.g.

http://someaddress.com/page/?mode=updated

You can access this string from js. Or set a js flag dynamically in the page that tells the box to show.

matpol
Thanks, but how can I pass the message contents to be displayed in the div to the reloaded page? I don't want to pass this in the query string.
TonE
A: 

I couldn't find a sensible way of dealing with this so added the message contents to the controller logic for the action to which the page is redirected. Probably should have done this in the first instance.

TonE