title: Returning the response from an Jquery AJAX call
body: <p>I have written a function, which has to check whether a username has been taken or not. Now when I call the function from another function, and alert it's return value:</p>
  
  <pre> alert(checkusernameavailable('justausername')); </pre>
  
  <p>it says 'undefined'. I've searched high and low, but can't find what I'm doing wrong. I guess it should just return the php-echo in check.php, but it doesn't. Here's the function I wrote:</p>
  
  <pre>var checkusernameavailable = function(value)  {
      $.ajax({
        url: "check.php",
        type: "POST",
        async: false,
        cache: false,
        data: "username=" + value + "",
  
        success: function(response) {
          alert(response);
          return response;        
        },
        error: function() {
          alert('ajax error');
        }
      });
    } </pre>
  
  <p>What am I doing wrong?</p>