Calling a function inside a jquery click event
<p>I am trying to call a function inside a <code>click</code> event with jQuery, but jQuery returns <code>undefined</code> when the function is called. What is the correct way to do this? </p>

<pre><code>$(document).ready(function() {
   $('#my_button').click(function() {
      var valid = check(something);
      if (valid) { // do something }
   });

   check = function(param) {
     .ajax {
         // ajax params
         success: function(data) { 
            if (data)
               return true;
         }
     }
   }
});
</code></pre>

<p>if you do a <code>console.log(valid)</code>, it is returned as <code>undefined</code></p>

<p><strong>UPDATE</strong>: I've added the code inside <code>check()</code>, which is an ajax call. That seems to be the problem. If I just do an <code>alert()</code> inside check, then everything works. So what's wrong with the ajax call?</p>
