What's the algorithm behind stack overflow's ajax tag search field
<p>I want to make an ajax auto complete field like stack overflow's tag search box(used to add favorite tags and add tags to your question). I used to call ajax every time key's up,but I think it's not efficient.</p>

<p>I find stack overflow does it well. I guess it would only call ajax when key's up and some time has passed. I then wrote these lines to test:</p>

<pre><code>$("#a").keyup(function(){
    clearTimeout(c);
    var c=setTimeout(alert("keyup and 0.5s have passed"),500);
})
</code></pre>

<p>it does alert after key up and after 0.5 seconds, but it alert several times as key up times. Does clearTimeout() suppose to stop setTimeout() to be executed? Why it doesn't work? What's the right way to do this?</p>
