Solved

DIV is not updated except after reloading the page

Posted on 2014-01-01
6
461 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

Expert Comment

by:Ray Paseur
ID: 39750190
0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 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