title: Why return not working after Ajax call jquery?
body: <p>I am not able get the returned value after ajax call. I can see that values are being returned but when I do <code>console.log()</code> it shows <code>undefined</code>. Is there something wrong in my approach.</p>
  <pre><code>var base_path = &quot;http://localhost/lab/theapp/api/&quot;
  
  $(function () {
    var url = base_path + &quot;tasks&quot;
    var type = &quot;post&quot;
    var data = &quot;&quot;
    var get = submit_me(type, data, url)
    console.log(get)
  })
  
  function submit_me(type, data, url) {
    try {
      $.ajax({
        url: url,
        type: type,
        data: data,
        dataType: &quot;json&quot;,
        beforeSend: function (request) {
          request.setRequestHeader(&quot;X-CSRF-Token&quot;, $.cookie(&quot;token&quot;))
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          //alert('page_login_submit - failed to login');
          console.log(JSON.stringify(XMLHttpRequest))
          console.log(JSON.stringify(textStatus))
          console.log(JSON.stringify(errorThrown))
        },
        success: function (r) {
          if (r.sessid) {
            var sessid = r.sessid
            var session_name = r.session_name
            var token = r.token
            jQuery.cookie(&quot;token&quot;, token)
            return r
          }
        },
      })
    } catch (error) {
      console.log(error)
    }
  }
  </code></pre>