?
Solved

DIV is not updated except after reloading the page

Posted on 2014-01-01
6
Medium Priority
?
462 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 2000 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 111

Expert Comment

by:Ray Paseur
ID: 39750190
0
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Suggested Courses

764 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