SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    (jquery) sessions

    I have a button that calls a php file that sets a session using ajax.

    is it possible to echo the results of that session without refreshing the page?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    I have a button that calls a php file that sets a session using ajax.

    is it possible to echo the results of that session without refreshing the page?
    Yes. The success method of the ajax call is where you can specify a function that accepts data from the php file, that data just being the text that the script echos out.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thank you for your response.

    I would like to echo the session which was just set, however it won't detect the new session without refreshing the page.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    Hi thank you for your response.

    I would like to echo the session which was just set, however it won't detect the new session without refreshing the page.
    It won't? That's odd, because this simple test seems to do that just fine.

    Code php:
    $setSession = filter_input(INPUT_GET, 'setSession', FILTER_SANITIZE_STRING);
    if ($setSession == 'true') {
        $date = date("D M j G:i:s T Y");
        $_SESSION['newDate'] = $date;
        echo $_SESSION['newDate'];
    }

    Code html4strict:
    <html>
    <head>
    </head>
    <body>
      <button id="sessionTest" value="set new date">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
      <script src="script.js"></script>
    </body>
    </html>

    Code javascript:
    $('#sessionTest').on('submit', function () {
        $.get('setSession.php?setSession=true', function (data) {
            $('body').append('<p>' + data + '</p>');
        });
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •