Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.getJSON back button showing JSON return data not the page

I have a little issue with my site. I have a page that hosts a google map. However the map does not get shown until the user clicks a button. It then call $.getJSON to get the addresses that i need to show on the map...

$.getJSON(theurl, function(json) {
  ...
}

It all works fine. However if the user then moves to a different page and then clicks the Back button they get the data from the $.getJSON call displayed, not the page itself.

It's as if the call to get the addresses has become part of the browsing history. If the user hits refresh when the data appears the full page then gets displayed.

Can anyone tell me how to stop this from happening.

I'm using the googlemap in an ASP.Net MVC site.

Thanks

like image 576
Richard Avatar asked Jan 10 '10 14:01

Richard


1 Answers

I solved it by including the below code just before the $.ajax function

$.ajaxSetup({ cache: false });

It works! Try it

like image 129
Matt Kramer Avatar answered Nov 02 '22 09:11

Matt Kramer