I have a page with several check boxes that needs to represent the state in a database. The check boxes are AJAX driven so when one is checked, a request is sent to update state in the database. If their view was stale the view for affected/related check boxes are updated, and user notified, and must try again. When I refresh I'd like the check boxes to represent what is actually returned in HTML generated from the data in the database, not some arbitrary previous user interactions with the input elements.
How do I make it so Firefox doesn't update these check boxes I've interacted with so they are identical to the state in the newly received HTML?
The problem is confusing because:
When I refresh a page in Firefox and the checked attribute for the check box is updated in the newly received HTML, Firefox will update the view, as I would expect it to.
However, if I interact with the check box, then refresh, THAT check box is not updated per the newly received HTML.
ie. It doesn't matter if checked="checked"
or the checked attribute is non-existant, Firerfox keeps it that way unless I do a shift-refresh.
I've even added window.onunload = function(){};
because I thought it might be due to the bfcache, but it is not.
Tried with the following headers and it still restored the state.
HTTP/1.1 200 OK
Date: Thu, 15 Mar 2012 21:19:02 GMT
Server: Apache/2.2.20 (Ubuntu)
Expires: 0
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate
Vary: Accept-Encoding
Content-Encoding: gzip
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html;charset=ISO-8859-1
Tried looping over the elements, and despite the checked attribute not existing in the source html, JavaScript considered the checked attribute to be "checked.", so there is no way to restore the value from the received source, after Firefox restores the value from previously entered input.
The converse is also true... the source says checked="checked"
and the onload JavaScript considers checked undefined
.
Source for alerting on the state of the first checkbox.
window.onload = function() {
$('input[type="checkbox"]').each(function() {
alert($(this).attr('checked'));
return false
});
}