Prevent Firefox from restoring the state of the previous user after updating

I have a page with several checkboxes that are supposed to represent the state in the database. Checkboxes are AJAX, so when one of them is checked, a request is sent to update the state in the database. If their view was out of date, the updated view for the linked / linked checkboxes is updated and the user is notified and must try again. When I update, I would like the checkboxes to display what is actually returned in the HTML generated from the data in the database, not some arbitrary previous user interactions with the input elements.

How do I prevent Firefox from updating those checkboxes that I was interacting with so they are identical to the state in the newly received HTML?

The problem is confusing because:

  • When I refresh the page in Firefox and the checked attribute for that checkbox is updated in the newly received HTML, Firefox refreshes the view as expected.

  • However, if I interact with this checkbox, then update the checkbox so that this checkbox doesn't update with the recently received HTML.

t. It doesn't matter if checked="checked"

or the checked attribute is nonexistent, Firerfox keeps it that way unless I update shift.

I even added window.onunload = function(){};

it because I thought it might be related to bfcache, but it isn't.

Tried the following headers and it was still restoring 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 for looping over elements, and despite the checked attribute not existing in the original html, JavaScript considered the checked attribute "checked". So there is no way to restore the value from the retrieved source after Firefox restores the value from the previously entered input.

The converse is also true ... the source says checked="checked"

and JavaScript with loading checks the checkbox undefined

.

The source to notify about the state of the first checkbox.

window.onload = function() {   
    $('input[type="checkbox"]').each(function() {
        alert($(this).attr('checked'));
        return false
    });
}

      

+3


source to share


1 answer


document.formname.reset()

worked which seems to be rebuilding from what it was originally originally. This is the only method I've tried that works ...

Thanks to Dennis for posting this answer on a similar question. Firefox: how to reload a form * without * caching user input?



The only problem with this solution is I don't need a form, I don't use a form, or I don't submit a form, etc. I use these checkboxes to create a UI which seems to be perfectly correct use but for this to work I needed to bind all my inputs to the form.

+1


source







All Articles