Solved

How to refresh DIV not all page?

Posted on 2009-05-13
4
547 Views
Last Modified: 2012-06-27
Hi all,

i need some help. I have a code that basicly its divided in two parts, left part is a streaming and right part its indicators (perl script inside the same page), this part needs to be refreshed all 2seconds, to give real-time statistics, but i dont want to reload the stream part.

its just one page examples.pl?refer that i call, and this gives the output in html. how can i do this?

Tks a lot people,
0
Comment
Question by:mpc650
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 24379886
Use AJAX to do this.

I use JQuery API, as it provides a higher level api / notation for this. Here is a way to do in JQuery.

You'll need to implement a way to call your script just to get the content you want. Below I implemented it as a different Perl script.

Get JQuery from jquery.com, its 1 file.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<script type="text/javascript" src="/js/jquery-1.3.2.js"></script>

<script type="text/javascript">

$(document).ready(function(){

  refreshDiv();

});
 

function refreshDiv() {

  $("#myDiv").load("/webapp/getdata.pl", function() { setTimeout("refreshDiv();", 2000); } );

}

</script>

</head>
 

<body>

<div id="myDiv">

</div>

</body>

</html>

Open in new window

0
 
LVL 39

Expert Comment

by:Adam314
ID: 24397871
I agree AJAX is the best way.  I've not used JQuery before, but didn't find the basic AJAX command to difficult to deal with.  Here is a very good tutorial on AJAX:
http://www.w3schools.com/ajax/default.asp
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24398345
@Adam: JQuery is nice and lightweight, and gives you sort of a functional syntax to deal with the DOM, as opposed to some of the other imperative style approaches. You should love JQuery since you are a Perl pro, you can do things like $.each(...) to traverse the DOM and call closures / functions.

For full AJAX development, there are more heavyweight libs that bring GUI toolkit with them, such as ExtJS, but its overkill for someone that just wants to do simple HTML / DIV work.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

920 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

12 Experts available now in Live!

Get 1:1 Help Now