0

I'm doing a python web app which returns the result of python function (selecting a random item from a list). I'm using the "random.choice()" function and then "return jsonify".

Then, on the HTML template, a button calls and displays the result. It's working perfectly well on the web with a PC, but on mobile Android browser, here's what happens: It works only ONCE: it generates the "random" choice and displays it, but when I click again, it doesn't generate a new one. And it keeps displaying the first result it generated and doesn't "refresh" or "relaunch" the function, although it works on the web on PC browsers.

But...but... it also works perfectly with an iOS web browser! Every new word generates without problem. So only on Android it stucks on the first word.

Any ideas why?

Thanks a lot!

davidism
  • 121,510
  • 29
  • 395
  • 339
Pavel Nekh
  • 31
  • 1
  • 1
    This is fairly common and is likely because of aggressive caching. If you add`+ "?" + new Date().getTime(),` to your ajax or whatever call it sees it as a new call and doesn't used cached information. Just to be clear you need to add this in your javascript/jquery call, not the python one. – Keef Baker Mar 21 '17 at 16:03
  • Thanks! I didn't do exactly this, but you helped me understand that it was a cache problem. I searched a bit and added this to my script: $.ajaxSetup({ cache: false }); And now it works – Pavel Nekh Mar 21 '17 at 16:10

1 Answers1

0

If you're still looking, it's a caching problem and you can add this code to make it go away:

$(document).ready(function() {
  $.ajaxSetup({ cache: false });
});

Answer found here: How to set cache false for getJSON in JQuery?

Community
  • 1
  • 1
Pavel Nekh
  • 31
  • 1