I'm making a web app to manage product SKUS. One part of that is to associate SKUs with product names. On each row of a table, I list a SKU and display a <select>
box with product names. The product that's currently associated with that SKU in the database is given an attribute like selected="selected"
. This can be changed and updated via AJAX.
There are a lot of product <option>
s - 103 to be exact - and this list is repeated in the <select>
on each row.
From another input on the page, I am using jQuery AJAX requests to add new SKU/product associations, and to make it clear that they're added instantly, I insert them into the top of the table with a little highlight effect. As the number of SKUs increases past 10 or so, if I refresh the page (which loads everything back out of the database ordered by product name), Firefox starts to show some wrong options as selected by default. It is not consistent about which incorrect option it shows, but it seems to be mixing up the options that existed before the page reload.
If I inspect the <select>
using Firebug, the select="selected"
is on the correct <option>
tag. Refreshing the page (or leaving and typing this page's URL back in to return) does not make it show up correctly, but hard refreshing (Ctrl+F5) does.
Both Chrome and IE7 display this correctly in the first place.
My theory is that this is a result of a faulty cache strategy by Firefox. Does that sound right? Is there any way I can say in my code "if this page is refreshed, make it a hard refresh - reload everything from scratch?"
Update
To solve this problem, I changed strategies.
- Previously, I put a
<select>
with a long list of <option>
s on each table row, with the current value set as default
- Now, I put the current value in a
<span>
. If the user clicks a "change" button, I replace the <span>
with a <select>
, and the "change" button becomes a "confirm" button. If they change options and click confirm, AJAX updates the database, the and the <select>
goes back to being a <span>
, this time with the new value.
This has two benefits:
- It fixes the bug described above
- It requires far fewer DOM elements on the page (all those redundant
<option>
s)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…