JSON return undefined from JQuery request
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1225667/how-to-return-ajax-response-text">How to return AJAX response Text?</a>  </p>
</blockquote>



<p>I'm trying to put together a JQuery timeout function for a form submit action. I have something similar in place via PHP for a page reload, and have the time of the initial page load stored in <code>$_SESSION['pageLoad']</code>. What I'm now trying to do is grab that value and use it in some JQuery math.</p>

<p>After searching around <a href="http://stackoverflow.com/questions/2765175/how-to-get-session-variables-from-php-server-with-ajax-function-php-html-js-aj?rq=1">SO</a>, I have arrived at the following:</p>

<p><strong>PHP</strong></p>

<pre><code>&lt;?php
    //filename: getsession.php
    session_start();
    echo json_encode($_SESSION['pageLoad']);
</code></pre>

<p><strong>JQuery</strong></p>

<pre><code>$("#sms-creator").submit(function() {
    var     session;
    $.ajaxSetup({cache: false})
    $.get('sms_includes/getsession.php', function(data) {
        session = data;
    });

    //at this point I just want to see what I'm getting, hence the next 2 lines...
    alert(session);
    return false;
});
</code></pre>

<p><em>The path to the PHP file is relative to the form page, not the .js file.</em></p>

<p>My alert only returns 'undefined'. I'm inexperienced with Javascript and its libraries, so the fault is not apparent to me. Any help appreciated.</p>
