Solved

DIV is not updated except after reloading the page

Posted on 2014-01-01
6
459 Views
Last Modified: 2014-01-01
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

0
Comment
Question by:Ashraf Hassanein
  • 3
  • 2
6 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39750156
If this variables are php variables (session or not) it's normal, you need to do update the document object model (the page) by yourself

check back my last proposition in your previous question :

if response look like :
{
   connected:true,
   username:"leakim971",
   userIP:"127.0.0.1",
   priviliges:"root;of;course",
   sessionDate:"12/31/1969",
   sessionTime:"20:00:00"
}

Open in new window


Test pages :
- Connected : http://jsfiddle.net/H699A/
- Not connected : http://jsfiddle.net/H699A/1/

The following replace line 32 to
$.post("check_session.php", {}, function(response){
	$("#logged-username-value").html(response.username);
	$("#logged-userIP-value").html(response.userIP);
	$("#logged-priviliges-value").html(response.priviliges);
	$("#logged-sesssionDate-value").html(response.sesssionDate);
	$("#logged-sesssionTime-value").html(response.sesssionTime);
	$("#status-block").css("display", response.connected?"block":"none");
	$("#toolbar-block").css("display", response.connected?"block":"none");
});

Open in new window

0
 

Author Comment

by:Ashraf Hassanein
ID: 39750186
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

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39750190
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 82

Expert Comment

by:leakim971
ID: 39750192
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

0
 

Author Comment

by:Ashraf Hassanein
ID: 39750226
Thank you so much it is working as it should be thanks for your help.
0
 

Author Closing Comment

by:Ashraf Hassanein
ID: 39750229
Very Helpful answer,
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hbo knew my windows software 4 60
php56-php-mcrypt for rhel7 php56 1 43
Using Specialized Fonts in CSS 1 23
MSSQL - Lock Row from reading by other programs 9 33
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question