Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    33
    Thanks
    18
    Thanked 0 Times in 0 Posts

    PHP Sessions: store status of jquery dialog

    Heya,

    beginner issue:

    I want to log the opened/closed status (autoOpen) of my jquery dialog through a php session. It opens through a double click on a button.

    Eventhough this sounds very simple, I have issues finding the best approach for that :/ With my current attempts, I always end up stuck somewhere in the middle...

    So any hint or direction would be welcome!

    Thanks in advance!

  • #2
    Regular Coder
    Join Date
    Nov 2012
    Posts
    109
    Thanks
    6
    Thanked 12 Times in 12 Posts
    Look into using jQuery's ajax possibilities, with this you can easily call an external PHP file and save the session variable there.

    It would be something like this:

    In your jQuery bit which handles the opening and closing of the jQuery dialog:
    Code:
    $.post("session.php", { status: "open"} );
    And then in session.php:
    PHP Code:
    session_start();
    $_SESSION['status'] =$_POST['status']; 
    Obviously this is the quick and easy way of doing it, without any checks whatsoever. If you're already using AJAX calls in your application, I usually merge them all together in one PHP file and use a switch to select the action that needs to be taken. That way, even if the file is called directly, nothing happens.

  • Users who have thanked Thyrosis for this post:

    coffeecup (03-10-2013)

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    33
    Thanks
    18
    Thanked 0 Times in 0 Posts
    thanks ALOT for that!

    once a window has been opened, I'd like to paste the text "open" or "closed" in a div dependant on its status.

    EDIT: new approach (still not working
    Code:
    $(document).ready(function() {
    	$(".windows").dialog({
    	autoOpen: false,
    	stack: true,
    	draggable: true,
    	position: [600, 200],
    	height: 500,
    	width: 650,
    			open: function( event, ui ) {
    
    				$.post("session.php", { status: "open"});
    				$("#status_w1").load("session.php");
    			},
    			close: function( event, ui ) {
    				$.post("session.php", { status: "close"});
    				$("#status_w1").load("session.php");
    			}
    	})
    #status_w1 is the div fyi.

    hm any hint on how to either fix or best approach this issue?

    thanks in advance!
    Last edited by coffeecup; 03-10-2013 at 10:31 PM.

  • #4
    Regular Coder
    Join Date
    Nov 2012
    Posts
    109
    Thanks
    6
    Thanked 12 Times in 12 Posts
    Hang on, so in the open function you post "open" to session.php, directly followed by loading session.php to get the status?

    If so, why not just do

    Code:
    $.post("session.php", { status: "open"});
    $("#status_w1").html("open");
    Or something?

  • Users who have thanked Thyrosis for this post:

    coffeecup (03-10-2013)

  • #5
    New Coder
    Join Date
    Jul 2012
    Posts
    33
    Thanks
    18
    Thanked 0 Times in 0 Posts
    thanks a ton, I managed to solve the issue now!


    Code:
    	$(".windows").dialog({
    	autoOpen: false,
    	stack: true,
    	draggable: true,
    	position: [600, 200],
    	height: 500,
    	width: 650,
    			open: function( event, ui ) {
    			$window = $(this).attr('id');
    			$.post("session.php", {"status":"open", "window":$window}, function(results) {
    			$('#logwindow').append(results);
    			});
    			},
    			close: function( event, ui ) {
    			$window = $(this).attr('id');
    			$.post("session.php", {"status":"closed", "window":$window}, function(results) {
    			$('#logwindow').append(results);
    			});
    			}
    	})
    session.php:
    Code:
    <?php
    session_start();
    
    $_SESSION[$_POST["window"]] = $_POST["status"];
    $parsetext = $_POST["window"] . ": " . $_SESSION[$_POST["window"]] . "<br/>";
    print $parsetext;
    ?>

  • #6
    Regular Coder
    Join Date
    Nov 2012
    Posts
    109
    Thanks
    6
    Thanked 12 Times in 12 Posts
    Glad I could point you in the right direction =)


  •  

    Posting Permissions

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