$ .getJSON back showing JSON return data, not page

I have a little problem with my site. I have a page that has a google map. However, the map is not displayed until the user clicks the button. Then it calls $ .getJSON to get the addresses that I need to show on the map ...

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

Everything works perfectly. However, if the user then goes to another page and then clicks the back button, they get the data from the call to $ .getJSON, and not the page itself.

As if the call to get addresses became part of the browsing history. If the user clicks the Refresh button when the data appears, a full page is displayed.

Can someone tell me how to stop this.

I am using googlemap on ASP.Net MVC site.

thanks

+6
javascript jquery asp.net-mvc
source share
3 answers

I solved this by including the code below immediately before the $ .ajax function

$. ajaxSetup ({cache: false});

It works! Try

+10
source share

This worked for me and works well with Rails controllers:

 $.getJSON(url, {format: 'json'}, successHandler); 

As a bonus, I can save the cache.

I'm sure this works for the same reason that cache: false works - both add a parameter to the URL so that Chrome doesn't get confused with the source. In this case, although I get caching the results, which is nice.

+4
source share

This is actually a bug in Chrome . I fixed this by adding something to the AJAX call url, so it is different from the page url (like "& ajax = true").

So, in your case, it will look like this:

 $.getJSON(theurl + '&ajax=true', function(json) { ... } 

(And, of course, you will need to check "?" And what is not in the request, but this illustrates the point.

+3
source share

All Articles