Tech Note: Out-of-Sync Ajax Comments Debugged

• Views: 4,230

Wee-oo wee-oo! Page reload alert! Wee-oo wee-oo!

Yes, it’s time to reload the page again, as we install the fix for another annoying bug in our Ajax comments. To be completely sure you’re up to date, you may also want to clear your browser cache before hitting the refresh button.

Non-techies may now proceed to the open thread…

Only techies left? OK, here’s the dirty low-down on this caper. When loading comments via Ajax, you need some way to identify the last displayed comment, so you can display any comments newer than that. Originally, in the Dark Ages of LGF’s Ajax Makeover, I coded this to use an embedded form, with hidden INPUT elements that kept track of these variables. After getting a batch of new comments, the hidden INPUTs would be updated with the new values via Javascript, so the next call to the Ajax routine would know where the new comments started.

The problem, however, is that some browsers apparently mess with the values of hidden INPUTs—especially when you have several tabs open to the same page, or several different LGF pages. I’m not certain, but it looks like these browsers are restoring default values into these INPUTs, when switching among open tabs. The problem would show up when you clicked the ‘new comments’ button; sometimes it would redisplay the last batch of new comments, so you’d end up with a whole section of duplicated comments.

So the new code installed tonight uses a much sturdier technique to keep track of the current last comment—it looks at the DOM itself, for the last comment within an overall container DIV, then finds a certain bit of embedded metadata within that last comment that contains the necessary values. This way, the out-of-sync comments problem is a thing of the past, because the code is always looking at the actual data that’s already been displayed.

The jQuery Metadata plugin is used to extract the data that’s embedded in each comment.

Another bug slain.

UPDATE at 2/28/08 5:23:01 pm:

Spoke too soon — still bugs lurking. Stand by; will be fixed soon.

UPDATE at 2/28/08 5:28:22 pm:

Wee-oo! Wee-oo! Another reload alert! Wee-oo wee-oo!

Everything is fixed; refresh your page once again and commenting will be smooth, effortless, and fancy free.

Jump to top

Create a PageThis is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2023-04-04 11:11 am PDT
LGF User's Guide RSS Feeds

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Cash.app
Recent PagesClick to refresh
Ranked-Choice Voting Has Challenged the Status Quo. Its Popularity Will Be Tested in November. JUNEAU — Alaska’s new election system — with open primaries and ranked voting — has been a model for those in other states who are frustrated by political polarization and a sense that voters lack real choice at the ...
Cheechako
5 days ago
Views: 176 • Comments: 0 • Rating: 0