title: JQuery ajax request inside a function: how to return the value I got?
body: <p>I want to write a javascript function, that will make an ajax request to PHP script and returns it's result. That's how it looks:</p>
  
  <pre><code>function myjsfunc(some_data)
  {
      $.post(
              "/myscript.php",
              { some_data: some_data },
              function(response)
              {
                  result = response;
              }
            );
      return result;
  }
  </code></pre>
  
  <p>The problem is, that <code>result</code> is always undefined. This might be because variable <code>result</code> is not in <code>myjsfunc</code> namespace? Or it is because success function result is received way after the main function is processed?</p>
  
  <p>Anyway, how can I get desired result? Is there a way?</p>