Ajax request to autocomplete an input field

Ajax request to autocomplete an input field

Hello all,

first sorry for my english.
I need help to make my ajax autocomplete zip code input field working properly.
The input has a maxlength attribute equal to 5. I use the ".post()" function to send the ajax request when the length of the input field reaches 5 caracters.
So far everything is working, the user enters a zip code and get all the cities back in a div from where he can choose his city.

But I've noticed in the Firebug plugin that when the user enters more than 5 caracters my function keeps sending some requests because I use the ".keyup()" function to check the length of the input field each time the user presses a key.

So my question is how can I prevent sending some requests after the input field has reached 5 caracters?

Thanks for your help