Tech Note: Out-of-Sync Ajax Comments Debugged

Charles Johnsonfollow me on twitter
Thu Feb 28, 2008 at 5:07 pm PST • Views: 200

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.

Advertisement

248 comments

^ back to top ^

Name:

Pass:

Register Forgot Your Password? Re-send Confirmation (To log in, cookies must be enabled in your browser!)

Turn off ads by subscribing!
For about 33 cents a day, our subscription option turns off all advertisements at LGF!
Read more...


► LGF Headlines

  • Loading...

► Tweeted Articles

  • Loading...

► Tweeted Pages

  • Loading...

► Top 10 Comments

  • Loading...

► Bottom Comments

  • Loading...

► Recent Comments

  • Loading...

► Tools/Info

► Tag Cloud

► Contact

You must have Javascript enabled to use the contact form.
Your email:

Subject:

Message:


Messages may be published in our weblog, unless you request otherwise.
Tech Note:
Using the Contact Form

More Partners

Compare Electricity Prices in your area. Texas Electricity is deregulated; you have the right to choose Texas Electric Rates from among many Texas Electric Companies.

But drill baby drill HAS substance until they can make a car and a house that can run on wind and solar AND make that car and house affordable!

TwitterFacebook
LGF Pages
Recent Pages

researchok
'I Was Looking Forward to a Quiet Old Age': Instead, Etta Shiber, Helped Smuggle Stranded Allied Soldiers To Freedom
1 hour, 19 minutes ago
Views: 36 • Comments: 0
Tweets: 0 • Rating: 0

Daniel Ballard
Late Afternoon Light-Kalanchoe
9 hours ago
Views: 88 • Comments: 0
Tweets: 0 • Rating: 3

MikeySDCA
Colin Powell Endorsed Same-Sex Marriage Once It Was Safe, More Evidence He's Hardly a Great Leader.
9 hours, 3 minutes ago
Views: 109 • Comments: 1
Tweets: 0 • Rating: 0

Eclectic Infidel
City College of San Francisco Budget Update
9 hours, 52 minutes ago
Views: 106 • Comments: 0
Tweets: 0 • Rating: 0

Michael McBacon
Kansas governor signs 'Shariah bill' to ban Islamic law
14 hours, 23 minutes ago
Views: 214 • Comments: 6
Tweets: 0 • Rating: 5

Aigle
National Geographic Traveler Veers Off Track
1 day, 14 hours ago
Views: 438 • Comments: 7
Tweets: 0 • Rating: -5

MichaelJ
Apple TV Slated to Debut in December?
1 day, 15 hours ago
Views: 216 • Comments: 0
Tweets: 0 • Rating: 1

Ascher
Israeli Who Saved Turk on Everest: You Never Abandon a Friend - Israel News, Ynetnews
1 day, 16 hours ago
Views: 291 • Comments: 1
Tweets: 0 • Rating: 3

Haywood Jabloeme
The Harrassment of Patterico & Its Roots in Left-Wing Activism
1 day, 17 hours ago
Views: 510 • Comments: 2
Tweets: 0 • Rating: 4

Curt
Brian Banks: (Video) Falsely accused of rape speaks out
1 day, 19 hours ago
Views: 263 • Comments: 2
Tweets: 0 • Rating: 4

 Frank says:

Kid's heads are filled with so many nonfacts that when they get out of school they're totally unprepared to do anything. They can't read, they can't write, they can't think. Talk about child abuse. The U.S. school system as a whole qualifies. -- Discussing the state of the education system in America - Playboy magazine, April 1993.