Show HN: How HN's upvote link works11 points·by asto·14 lat temu·6 commentsEach link has an anchor tag like this: <a href="vote?for=4156127&dir=up&by=asto&auth=12345&whence=%6e%65%77%73" id="up_4156127"> <img vspace="3" hspace="2" border="0" src="http://ycombinator.com/images/grayarrow.gif"> </a> The vote function looks like this: function vote(node) { var v = node.id.split(/_/); // {'up', '123'} var item = v[1]; // hide arrows byId('up_' + item).style.visibility = 'hidden'; byId('down_' + item).style.visibility = 'hidden'; // ping server var ping = new Image(); ping.src = node.href; return false; // cancel browser nav byId is getElementById. I don't know about you guys but I thought this was pretty neat!2 commentsPost comment[–]jgrahamc·14 lat temureplyWhich part did you find neat?[–]asto·14 lat temureply//ping server[–]Xymak1y·14 lat temureplyIt's an interesting way to not use XMLHttpRequest for Ajax.[–]Spoom·14 lat temureplyI'm curious; why didn't they use an AJAX request?[–]asto·14 lat temureplyBackward compatibility with really old browsers is all I can think of.[–]ImJasonH·14 lat temureplyIt's also much less code. It only really works if you don't care about the content of the response, though you could add an onerror handler that would fire on all error cases.
The vote function looks like this:
byId is getElementById. I don't know about you guys but I thought this was pretty neat!