Problem with return in $.post

Problem with return in $.post

Hi everybody !

I have some problem using the $.post function !

I wrote a function that test if a username is already used in my database.
That function must return true if the username is free and false in the other case :)

My problem is that I use the $.post function and i put the return true; and return false; in the callback function.
So it's the callback function that returns true/false instead of my function !

I d'ont know what to do :/

Here is my code :
  1. function validateName()
  2. {
  3. $.post("ajax_is_name_used.php",
  4. {name: $form_name.val()}, function(data) {
  5. if (data.success == 1) {
  6. $form_name.addClass("error");
  7. return false; // Problem, we are in the callback function !
  8. }
  9. else {
  10. return true; // Problem, we are in the callback function !
  11. }
  12. }, "json");
  13. }
Thanks a lot for your help :)

Pollop.