title: jQuery: variable is not sent from function
body: <p>I have a simple function that retrieves a setting from cakephp core using ajax. But returning this value gives back undefined. I have been looking at the code and searching the web on what I am doing wrong, but I still do not seem to see it. It's probably cuz of my long working day that I am overlooking something stupid. Maybe you guys can help me clear up my mind here... What goes wrong is mentioned in the comments of below code:</p>
  
  <pre><code>$(document).ready( function() {
      // check session timeout setting from cakephp core
      var checkTimeoutSetting = function() {
          $.ajax({
              url: '/users/checktimeout',
              type: "POST",
              success: function (data, textStatus, jqXHR) {
                  // data is logged as 60 on page load
                  console.log(data);
                  return data;
              }
          });
      };
      var sessiontimeout = checkTimeoutSetting();
      console.log('session: '+sessiontimeout);
      // sessiontimeout seems undefined now :(
      $("#remaining-session-time").html(sessiontimeout);
  });
  </code></pre>
  
  <p>Also tried this with making <code>sessiontimeout</code> a global variable, but still gives the same <code>undefined</code> message in my console.log</p>