form validation combined with ajax

form validation combined with ajax

I'm trying to make a username form validation combined with ajax but I'm stuck at 1 point. I need to use a var that is outside of my $.get() function so that I can add the function to the validate plugin.

This is what I have:

  1. jQuery.validator.addMethod("username", function(value, element) {
  2.      var result = false;
  3.      $.get("includes/checkUsername.php?user="+value, function(data){
  4.      if(data == "0") {
  5.      result = true;
  6.      }
  7.      });
  8.      return result;
  9.     }, "Username not available");
As you can see, I'm trying to change the value of "var result" to true, but since that is outside of my $.get() it doesn't seem to happen. I tried to put the return command inside the $.get function, but then my validator always keep saying it's a false check.

Is there anyway I can call that var inside my $.get function?