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 :
- function validateName()
- {
- $.post("ajax_is_name_used.php",
- {name: $form_name.val()}, function(data) {
- if (data.success == 1) {
- $form_name.addClass("error");
- return false; // Problem, we are in the callback function !
- }
- else {
- return true; // Problem, we are in the callback function !
- }
- }, "json");
- }
Thanks a lot for your help :)
Pollop.