Link to home
Start Free TrialLog in
Avatar of Ashraf Hassanein
Ashraf Hassanein

asked on

DIV is not updated except after reloading the page

I have the following page which has the DIV statusblock where it should be getting some variables by executing an inline PHP script, but these variables are only updated after reloading the page manually and not based upon the first display of the file, the code I am use is:

<div class="ribbon" id="ribbon">
<strong class="ribboncontent" id="ribboncontent"><img src="../images/hassans.gif" alt="Hassans" width="150" height="75"></strong>
</div>
<div  id="statusblock">
       <p id="statusdata"><?php  $statusHeader = $_SESSION['statusHeader'];
                                 echo $statusHeader;
                          ?></p>
</div>
<div id="toolbarblock">
<div id="headertoolbar" class="ui-widget-header ui-corner-all">
<button id="logout">Logout</button>
<button id="settings">Settings</button>
</div>
  <ul id="toolbarmenu" >
    <li><a href="#">Open...</a></li>
    <li><a href="#">Save</a></li>
    <li><a href="#">Delete</a></li>
  </ul>
</div>

                <script>
                 $( document ).ready(function() {
                        var $logout = $("#logout").button({ text: false, icons: { primary: "ui-icon-key" } });
                        var $settings = $("#settings").button({ text: false, icons: { primary: "ui-icon-gear", secondary: "ui-icon-triangle-1-s" } });
                        var $menu = $("#settings").parent().next().show();

                $(document).click(function() {
                        $menu.hide();
                $settings.removeClass("active");
                });
                $logout.click(function() {
                                      $.ajax({
                                              url: 'logout.php',
                                              type: 'POST',
                                              data: {},
                                              success: function(response){
                                               alert (response);
                                               $("#header").load("logo.php");
                                               $("#menu").load("menu.php");
                                               $("#main").load("login.php");
                                      }
                                      });

                        });
                $settings.click(function(evt) {
                        evt.stopImmediatePropagation();
                        $(this).toggleClass("active")
                        $menu.css("display", $(this).hasClass("active")?"block":"none");
                        $menu.position({ my: "left top", at: "left bottom", of: this });
                        });

                $settings.parent().buttonset().next().hide().menu();

                $menu.hover(function() {
                $(this).addClass("overme");
                }, function() {
                        if($(this).hasClass("overme")) {
                                $(this).hide();
                                $(this).removeClass("overme");
                                $settings.removeClass("active");
                                }
                        });

                $menu.click(function(evt) {
                        alert($(evt.target).text());
                        });
                });
                </script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ashraf Hassanein
Ashraf Hassanein

ASKER

So the response has to be an array as:
 $response = array();
 $response['connected']  = "true" ;
 $response['username']  = "leakim971" ;
 $response['userIP']  = "127.0.0.1" ;
 $response['priviliges']  = "root" ;
 $response['sessionDate']  = "12/31/1969" ;
 $response['sessionTime']  = "20:00:00" ;
 print_r($response);

Open in new window


Or as String:
$response="{";
$response=$response. "connected:true,";
$response=$response. 'username:"leakim971",';
$response=$response. 'userIP:"127.0.0.1",';
$response=$response. 'priviliges:"root;of;course",';
$response=$response. 'sessionDate:"12/31/1969",';
$response=$response. 'sessionTime:"20:00:00"';
$response=$response. "}";
echo $reponse;

Open in new window

should be json content :
<?php
 header('Content-type: application/json');
 $response = array();
 $response['connected']  = "true" ;
 $response['username']  = "leakim971" ;
 $response['userIP']  = "127.0.0.1" ;
 $response['priviliges']  = "root" ;
 $response['sessionDate']  = "12/31/1969" ;
 $response['sessionTime']  = "20:00:00" ;
 echo json_encode($response);
?>

Open in new window

your string, if valid, may be used too if the header is application/json

<?PHP
header('Content-type: application/json');

$response="{";
$response=$response. "connected:true,";
$response=$response. 'username:"leakim971",';
$response=$response. 'userIP:"127.0.0.1",';
$response=$response. 'priviliges:"root;of;course",';
$response=$response. 'sessionDate:"12/31/1969",';
$response=$response. 'sessionTime:"20:00:00"';
$response=$response. "}";
echo $reponse;
?>

Open in new window

Thank you so much it is working as it should be thanks for your help.
Very Helpful answer,