Solved

DIV is not updated except after reloading the page

Posted on 2014-01-01
6
452 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 108

Expert Comment

by:Ray Paseur
ID: 39750190
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now