title: JQuery returning undefined when it should return an int
body: <p>I'm very new to JQuery but am really putting forth an effort to learn more about it. I've written a function that I'm expecting a return value back from but am only getting undefined. Can someone please show me where I'm going wrong?</p>
  
  <p>Here is my code.</p>
  
  <pre><code>function test(){
    $.ajax({
      url:"",
      dataType:"json",
      type:'POST',
      data:{countMedia:'true'},
      success:function(data){
  return data.value;
      }
    });
  }
  
  alert(test()); // returns undefined when it should return an int value
  </code></pre>
  
  <p>Also, am I allowed to write a function inside of document ready? This is where I need to use it.</p>