/    Sign up×
Community /Pin to ProfileBookmark

Browser caching problem – POST

I have a Javascript file that interacts with a PHP server side script via a POST using AJAX. The JS is executed when an item is selected from a drop down (SELECT) and triggers the PHP file (guardIFRAMEroster.php), posting to it parameters configured by the JS based on the selection made from the drop down (SELECT). The PHP scipt file then outputs HTML to an iFrame that forms part of the current page loaded by the browser.

As part of loading the page from which all of this is driven, the PHP script file (that constructs the iFrame HTML content) is retrieved by the browser (with no qualifying parameters) via GET. So, when the page that “owns” the iFrame is loaded, the PHP script file is read from the server via GET as well. The response to this GET from the PHP script is invalid/incomplete at this point as no qualifying parameters were included as part of the call to the server. At this stage this is not an issue as the iFrame is not initially displayed and only becomes viewable once a selection is made from the drop down list (SELECT).

This (GET image) seems to be the cause of the subsequent cache issue described here after.

By the time the POST is done to the PHP server side script based on the drop down selection the user makes and it writes back to the browser, the cached GET image is displayed by the browser and not the most recent and valid output from the PHP script (have tried different browsers with same result). No matter what I try, I can’t get this to work. I have Googled for and tried various approaches (seems to be a few AJAX as well as FF caching issues around) including randamozing the parameters POSTed to the PHP script (with superfluous date integer value as added parameter) with no luck. I have even tried various work-arounds reported by Bugzilla bug report 183470 (Caches no-cache pages) with no success :-(. ([url]https://bugzilla.mozilla.org/show_bug.cgi?id=183470[/url]).

I have also confirmed that the issue is related to the output generated by the PHP script and not related to the request data sent from/posted by the JS script, i.e. the PHP script is triggered or receives a request for both the GET and POST scenarios and outputs (writes) back to the browser based on the calling parameters as expected (GET invalid/incomplete, POST valid). Is just that the output the browser displays is always that of the initial GET and not the last POST done.

As part of debugging this issue, I’ve also used Httpfox (firefox HTTP debugger) to confirm the HTTP exchange as part of the POST performed and it reports the following error as part of processing/decoding the content of the POST response (from the PHP script):
Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED)

This would imply there’s a disconnection between HTTP headers and content of some sort (header reports no cache, but for whatever reason the browser still thinks the content is cached)?
I have attempted to manipulate caching as best I can from both the JS and PHP script sides (Pragma and Cache-Control are both set to no-cache on request and for PHP response, Cache-Control is set to no-store, no-cache, must-revalidate, post-check=0, pre-check=0 and Pragma to no-cahce).

The headers look as follows:
Request:
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.11) Gecko/20101013 Ubuntu/9.04 (jaunty) Firefox/3.6.11
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: chrome://global/locale/intl.properties
Accept-Encoding: gzip,deflate
Accept-Charset: chrome://global-platform/locale/intl.properties,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
If-Modified-Since: Sat, 1 Jan 2000 00:00:00 GMT
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: PHPSESSID=b7ddf9f5aee9d6f91c4208975fce69ef; no-cookie
Referer: [url]http://localhost/guardIFRAMEprgms.php[/url]
Content-Length: 41
Pragma: no-cache
Cache-Control: no-cache

Response:
Date: Tue, 26 Oct 2010 17:42:44 GMT
Server: Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.6 with Suhosin-Patch
X-Powered-By: PHP/5.2.6-3ubuntu4.6
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 1603
Keep-Alive: timeout=15, max=76
Connection: Keep-Alive
Content-Type: text/html

I have attached two images to this post. The one showing GET and POST requests (for PHP script file guardIFRAMEroster.php) which also shows the headers for the POST interaction, the other the Httpfox trace showing the NOT CACHED (content) error.

Any suggestions would be greatly appreciated.

[upl-file uuid=392d9711-d77c-4b94-9a1a-7d8f3305874b size=44kB]Screenshot-HttpFox.png[/upl-file]

[upl-file uuid=417081e6-4269-4ac3-9ed2-ce0462eeb086 size=104kB]Screenshot-Firebug.gif[/upl-file]

to post a comment
HTML

0Be the first to comment 😎

×

Success!

Help @bokfok spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...