0

short: I am Newbie, but I try the best to ask straight forward, but please try to be forgiving with me ;)

I was searching for a solution to my problem for a while and two topics:

  1. Prevent browser caching of jQuery AJAX call result
  2. Can you clear jquery ajax cache?

come close and show some wonderful solutions, unfortunately they do not work with my situation.

I need to send a CGI command to an IP Camera using the jQuery.ajax() call. I am getting and often changing result. So I can not allow the browser to cache the result! I know and often read about this option (see topic 1.):

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

But this doesn't work in my case, as the camera CGI command structure does not work with the timestamp attached to the command. So instead of getting the answer I need, I will get an error.

After that I thought, I can adopt the jQuery Code to remove the timestamp that is attached when you set the option 'cache: false'. But after I read some comments (see topic 2.):

So if you use cache: false, jQuery just add an additional parameter to the URL with a current time. It makes for the local browser the URL another as it probably has in the local cache and it forward the request to the server. Nothing more.

So I figured out that would not help me neither.

One solution of topic 2 would be to add "Cache-Control" equal to "max-age=0", which switch off local cashing, in the server response header. But again it simply does not work for me, as I have no access or whatsoever to the Software of the IP Camera.

I think one solution would be to deactivate or delete the caching for that specific call. Another solution might be to stop the caching by any other way.

So does anybody have an idea, how I can make the web browser stop using the cached answers, when I call the ajax event two times in a row? (reload the site would help, but is also a no go in that case).

Thanks for all the answers in advance, if you need more information to make my problem more clear, feel free to ask.

regards, lihume

Community
  • 1
  • 1
lihume
  • 1
  • 1
  • 2
  • So what are you requesting, a url? What is the response? Is it a stream, or what? It is not clear why exactly you need to clear the cache. – Registered User Apr 15 '12 at 23:26
  • I use the cameras build in CGI command to get a status of a setting. As example I am asking "are the IR LED's set on or off" - 'param.cgi?cmd=getinfrared' - the answer is a variable: 'var infraredstat=on' ; now when I change this using another CGI command 'param.cgi?cmd=setinfrared&-infraredstat=off' and reopen the site, it will not show the current state, as due caching I still will get the old result that the IR LED's are off. – lihume Apr 16 '12 at 06:04

2 Answers2

0

Try adding a random argument with every request. param.cgi?cmd=getinfrared&fixme=21EC2020-3AEA-1069-A2DD-08002B30309D

Generate a new GUID with every request and this will make the browser think that it is requesting a new resource for the first time. The CGI software should just ignore the additional argument...

Registered User
  • 3,535
  • 10
  • 39
  • 63
  • I tried it, but it doesn't work! The CGI command is kind of strict. Adding any additional, not expected argument like a timestamp or a GUID results in an error. – lihume Apr 16 '12 at 17:36
0

You did not specify what server you are using, so I am not sure if this will work for you.

What you can do is use .htaccess

This should work with all Unix type servers, but you need full access permissions to install this.

<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>

Here is a thread about how to use Htaccess on IIS

http://forums.iis.net/t/1151878.aspx

Registered User
  • 3,535
  • 10
  • 39
  • 63