title: How to get return value in a function with inside Ajax call - JQuery
body: <p>this may sound very easy to few of you, but i am not able to figure out why I am not able to get the return value, even after chceking many posts :(</p>
  
  <pre><code>function getMessageCount() {
                      var count;
                      $.ajax({
                          type: "POST",
                          url: "http://localhost:43390" + "/services/DiscussionWidgetService.asmx/GetMessageCount",
                          dataType: "json",
                          contentType: "application/json; charset=utf-8",
                          success: function (data) {                            
                              count = data.d;
                          } //success
                      });
                      return count;
                  }
  </code></pre>
  
  <p>Now if I call <code>var count = getMessageCount()</code>;
  it gives me undefinted :(
  while inside the method count is coming correct, i.e. service is working fine.</p>