How to get the value that return from the javascript function?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/12550002/how-to-return-the-value-of-a-function-after-the-result-of-an-ajax-call-has-come">How to return the value of a function after the result of an ajax call has come?</a>  </p>
</blockquote>



<p>I have one function that use to count the quantity of item in my controller.</p>

<pre><code>function GetQtyItem() {
  var qty;
  var urlQuantity = "Quotation/CountQuantity";
  $.getJSON(urlQuantity, function (quantity) {
      qty = quantity.ja;
  });
  alert(qty); //3
  return qty;
}
</code></pre>

<p>I included the file name with the correct part, and called this function in another view of my asp.net mvc project :</p>

<pre><code>&lt;script language="javascript" type="text/javascript"&gt;
  var i = GetQtyItem();
  alert(i);
&lt;/script&gt;
</code></pre>

<p>But the result in the alert dialog is <code>Undefined</code>.</p>

<p>Could any one tell me, how can I alert it with the correct value(3). Thanks in advanced.</p>
