Reputation: 8801
I'm having a peculiar problem:
PHP SCRIPT:
// checks If-Modified-Since header (if nothing has changed)
// Sends HTTP/1.0 304 Not Modified
// Sends Cache-control: public, must-revalidate
// exits
// if NO If-Modified-Since or something has changed
// builds content
// Sends Last-Modified: [DATE TIME]
// Sends Cache-control: public, must-revalidate
// exits
I am using jQuery AJAX to attempt to refresh the content on demand, I am trying to do this by altering the If-Modified-Since header with a DATE TIME in the past, using the "beforeSend" param.
This is currently what happens:
I guess im under the impression that at step #4, the browsers content should have been refreshed, what am i missing?
I setup a little test so you can try and see what i mean: http://tweetplenty.com/test/test2.php ... use FF and firebug if you can as im using console.log() ... here is the order of operations:
the "normal" link will do a request to http://tweetplenty.com/test/test.php without modifying if-modified-since ... subsequent requests using the "normal" link should return a 304 (it should return 200 OK every 60 seconds)
the "if-modified-since" link will do a request to http://tweetplenty.com/test/test.php WITH modified if-modified-since header, the browser will return new content.
clicking "normal" again at this point returns the previously cached data, I would think that it should have refreshed the data after clicking the "if-modified-since" link.
If you want to checkout the test scripts themselves here you go: http://tweetplenty.com/test/test.zip
Upvotes: 2
Views: 2204
Reputation: 5335
when making requests via the XmlHttpRequest to get any modified content from your server script you should append some variable that changes at the end of the querystring.
For example if your script is
mydomain.com/myscript.php
then a way to call it via let's say Jquery Ajax is to make a request at
mydomain.com/myscript.php?t=[some_value].
Usually [t] can be the current time in milliseconds or an other number.
In other words try to create a unique URL each time you send a request via the XMLHttpRequest Object.
As for the Cache-Control header there are more options that you should have a look at.
Regards,
Upvotes: 0
Reputation: 31761
I think you want to modify the headers on all requests coming in. Check out example #2 on this page.
Upvotes: 1
Reputation: 189696
Sounds like some level of caching between the jquery script and the PHP script. I would suspect browser-level caching. (although it could theoretically be proxy caching, I guess)
Have you tried using curl or a web browser to try your AJAX request manually?
Upvotes: 0