472,808 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,808 software developers and data experts.

Ajax does not display a DIV which contains a html page with javascript

6
Hi,

I have been experiencing an issue when trying to use AJAX to reload a DIV area
using a timer of 2000ms, which contains a html page with another DIV and javascript.

Scenario
-------------
I have perl script which simply runs a ps on a Solaris server and generates
a static html page with all of the code perfectly and this html page works fine
when viewing it statically or with a META REFRESH header tag. The idea is to give the user the appearance of a live cpu graph in a runtime fashion.

I have 4 servers being monitored which are all conaitned within an IFRAME html
page, each refreshing every 2 seconds. This works fine but very visually
annoying.

So I decided to use AJAX to refresh the page. The ajax code uses a timed value
of 2000ms and refreshes the page with hopefully a lot less flickering to the user.

The ajax script I have works 100% for a static or CGI generated page and
updates the DIV accordingly.

When I try to update the AJAX div with the very basic HTML page containing
the graph information which works statically, the graph does not appear within
the ajax div. If I place some text before and after the code which creates the
graphs that data appears fine.

Would anyone know why this could be happenning?

The ajax script will only return Foo and Bar on the page and not the graph.

The javascript code I am calling/using with the lg.html page can be found at
http://www.sbmkpm.com/line.html

The basic code for the graph is as follows. (lg.html)
------>
Foo

Expand|Select|Wrap|Line Numbers
  1. <!-- graph code begins here-->
  2. <script type="text/javascript" src="wz_jsgraphics.js"></script>
  3. <script type="text/javascript" src="line.js"></script>
  4.  
  5. <div id="lineCanvas"> </div>
  6. <script type="text/javascript">
  7. var g = new line_graph();
  8. g.add('0', 14);
  9. g.add('1', 9);
  10. g.setMax(100);g.setColor(4);
  11. g.render("lineCanvas", "CPU Usage");
  12. </script>
Bar
<------

The basic code for the ajax (refresh script) is as follows. (cpu_load.html)
------>
[HTML]<html>
<head>
<title>messages</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function sndReq() {
http.open('get', 'lg.html');
http.onreadystatechange = handleResponse;
http.send(true);
setTimeout("sndReq()", 2000); // Recursive JavaScript function calls sndReq()
every 2 seconds
}

function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
if (response != responseold || responsecheck != 1) {
var responsecheck = 1;
document.getElementById("messages").innerHTML = http.responseText;
var responseold = response;
}
}
}
</script>

</head>

<body onLoad="javascript:sndReq();">
<div id="messages"></div>
</body>
</html>[/HTML]

<------

As you can see, the get routine, simply calls the lg.html page every 2000ms
which updates the div "messages" area with the html page lg.html page.

Sometimes, when I first manually refresh the page, the graph will flicker and then dissapear without a trace.

If someone could help me with this frustrating issue, I would greatly appreciate
your help, as I have tried numerous options to get the graph to appear. I also don;t think it is specifically related the js scripts I am calling, but perhaps more to the way in which I am trying to do it.

Thanks,

PT
Sep 25 '07 #1
10 3351
dmjpro
2,476 2GB
Hi,

I have been experiencing an issue when trying to use AJAX to reload a DIV area
using a timer of 2000ms, which contains a html page with another DIV and javascript.

Scenario
-------------
I have perl script which simply runs a ps on a Solaris server and generates
a static html page with all of the code perfectly and this html page works fine
when viewing it statically or with a META REFRESH header tag. The idea is to give the user the appearance of a live cpu graph in a runtime fashion.

I have 4 servers being monitored which are all conaitned within an IFRAME html
page, each refreshing every 2 seconds. This works fine but very visually
annoying.

So I decided to use AJAX to refresh the page. The ajax code uses a timed value
of 2000ms and refreshes the page with hopefully a lot less flickering to the user.

The ajax script I have works 100% for a static or CGI generated page and
updates the DIV accordingly.

When I try to update the AJAX div with the very basic HTML page containing
the graph information which works statically, the graph does not appear within
the ajax div. If I place some text before and after the code which creates the
graphs that data appears fine.

Would anyone know why this could be happenning?

The ajax script will only return Foo and Bar on the page and not the graph.

The javascript code I am calling/using with the lg.html page can be found at
http://www.sbmkpm.com/line.html

The basic code for the graph is as follows. (lg.html)
------>
Foo

Expand|Select|Wrap|Line Numbers
  1. <!-- graph code begins here-->
  2. <script type="text/javascript" src="wz_jsgraphics.js"></script>
  3. <script type="text/javascript" src="line.js"></script>
  4.  
  5. <div id="lineCanvas"> </div>
  6. <script type="text/javascript">
  7. var g = new line_graph();
  8. g.add('0', 14);
  9. g.add('1', 9);
  10. g.setMax(100);g.setColor(4);
  11. g.render("lineCanvas", "CPU Usage");
  12. </script>
Bar
<------

The basic code for the ajax (refresh script) is as follows. (cpu_load.html)
------>
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>messages</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <script>
  6. function createRequestObject() {
  7. var ro;
  8. var browser = navigator.appName;
  9. if(browser == "Microsoft Internet Explorer"){
  10.    ro = new ActiveXObject("Microsoft.XMLHTTP");
  11. }else{
  12.    ro = new XMLHttpRequest();
  13. }
  14. return ro;
  15. }
  16.  
  17. var http = createRequestObject();
  18.  
  19. function sndReq() {
  20.    http.open('get', 'lg.html');
  21.    http.onreadystatechange = handleResponse;
  22.    http.send(true);
  23.    setTimeout("sndReq()", 2000); // Recursive JavaScript function calls sndReq()
  24. every 2 seconds
  25. }
  26.  
  27. function handleResponse() {
  28.    if(http.readyState == 4){
  29.       var response = http.responseText;
  30.       if (response != responseold || responsecheck != 1) {
  31.          var responsecheck = 1;
  32.          document.getElementById("messages").innerHTML = http.responseText;
  33.          var responseold = response;
  34.       }
  35.    }
  36. }
  37. </script>
  38.  
  39. </head>
  40.  
  41. <body onLoad="javascript:sndReq();">
  42. <div id="messages"></div>
  43. </body>
  44. </html>
<------

As you can see, the get routine, simply calls the lg.html page every 2000ms
which updates the div "messages" area with the html page lg.html page.

Sometimes, when I first manually refresh the page, the graph will flicker and then dissapear without a trace.

If someone could help me with this frustrating issue, I would greatly appreciate
your help, as I have tried numerous options to get the graph to appear. I also don;t think it is specifically related the js scripts I am calling, but perhaps more to the way in which I am trying to do it.

Thanks,

PT
Make your static page dynamic as it does not work with static.
Actually the AJAX is not for Static page upload.

Kind regards,
Dmjpro.
Sep 25 '07 #2
paulie
6
Make your static page dynamic as it does not work with static.
Actually the AJAX is not for Static page upload.

Kind regards,
Dmjpro.
Hi,

Thanks for the feedback.

Do you mean, get a pl script or something like that which prints out the same
data as what would appear in the static generated page?

Cheers.
Sep 25 '07 #3
dmjpro
2,476 2GB
Hi,

Thanks for the feedback.

Do you mean, get a pl script or something like that which prints out the same
data as what would appear in the static generated page?

Cheers.
Yeah! :-)

You tried that and what's your O/P?

Kind regards,
Dmjpro.
Sep 25 '07 #4
gits
5,390 Expert Mod 4TB
heya pauli,

please use the code tags when posting source code ... for example

[CODE=javascript] code goes here [/code]

kind regards
Sep 25 '07 #5
paulie
6
Hi,

I will give that a go today and let you know. Sorry about the CODE thing.

Cheers.
Sep 26 '07 #6
paulie
6
Hi Dmjpro

I hope I have done the right thing here.

I gave that a go and got exactly the same result. All that is printed on the screen is Foo and Bar. I tested the PERL script out directly and the graph
is displayed ok. I have supplied the changes I have done below.

It's not super important, but just frustrating as the AJAX reload works fine
with everything else I have thrown at it so far that does'nt use another DIV with Javascript :(

EG: lg.html
Expand|Select|Wrap|Line Numbers
  1. <div id="lineCanvas" style="border:3px solid #ccc;">
  2. Print Something in here
  3. <FORM> <INPUT TYPE=SUBMIT></FORM>
  4. </div>
  5.  
Expand|Select|Wrap|Line Numbers
  1. function sndReq() {
  2.    http.open('get', '/mrtg/cgi-bin/lg.pl');
  3.    http.onreadystatechange = handleResponse;
  4.    http.send(true);
  5.    setTimeout("sndReq()", 2000); // Recursive JavaScript function calls sndReq() every 2 seconds
  6. }
  7.  
The lg.pl looks like this.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. use CGI qw(:standard);
  4. print header();
  5.  
  6. print <<EOF;
  7. Foo
  8.  
  9. <!-- graph code begins here-->
  10. <script type="text/javascript" src="/mrtg/wz_jsgraphics.js"></script>
  11. <script type="text/javascript" src="/mrtg/line.js"></script>
  12. <div id="lineCanvas"></div>
  13.  
  14. <script type="text/javascript">
  15. var g = new line_graph();
  16. g.add('0', 14);
  17. g.add('1', 9);
  18. g.add('2', 17);
  19. g.setMax(100);g.setColor(4);
  20. g.render("lineCanvas", "Heap Usage");
  21. </script>
  22. Bar
  23. EOF
  24.  
  25.  
Sep 26 '07 #7
dmjpro
2,476 2GB
Hi Dmjpro

I hope I have done the right thing here.

I gave that a go and got exactly the same result. All that is printed on the screen is Foo and Bar. I tested the PERL script out directly and the graph
is displayed ok. I have supplied the changes I have done below.

It's not super important, but just frustrating as the AJAX reload works fine
with everything else I have thrown at it so far that does'nt use another DIV with Javascript :(

EG: lg.html
Expand|Select|Wrap|Line Numbers
  1. <div id="lineCanvas" style="border:3px solid #ccc;">
  2. Print Something in here
  3. <FORM> <INPUT TYPE=SUBMIT></FORM>
  4. </div>
  5.  
Expand|Select|Wrap|Line Numbers
  1. function sndReq() {
  2.    http.open('get', '/mrtg/cgi-bin/lg.pl');
  3.    http.onreadystatechange = handleResponse;
  4.    http.send(true);
  5.    setTimeout("sndReq()", 2000); // Recursive JavaScript function calls sndReq() every 2 seconds
  6. }
  7.  
The lg.pl looks like this.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. use CGI qw(:standard);
  4. print header();
  5.  
  6. print <<EOF;
  7. Foo
  8.  
  9. <!-- graph code begins here-->
  10. <script type="text/javascript" src="/mrtg/wz_jsgraphics.js"></script>
  11. <script type="text/javascript" src="/mrtg/line.js"></script>
  12. <div id="lineCanvas"></div>
  13.  
  14. <script type="text/javascript">
  15. var g = new line_graph();
  16. g.add('0', 14);
  17. g.add('1', 9);
  18. g.add('2', 17);
  19. g.setMax(100);g.setColor(4);
  20. g.render("lineCanvas", "Heap Usage");
  21. </script>
  22. Bar
  23. EOF
  24.  
  25.  
Good :-)
Where is this line?
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("lineCanvas").iinerHTML = http.responseText
Kind regards,
Dmjpro.
Sep 26 '07 #8
paulie
6
Howdy,

Umm, it's still there but it refers to the messages DIV. This is the static html page which calls the perl script. The lineCanvas DIV is in the perl script, which
the graphing script updates.

Expand|Select|Wrap|Line Numbers
  1. function sndReq() {
  2.    http.open('get', '/mrtg/cgi-bin/lg.pl);
  3.    http.onreadystatechange = handleResponse;
  4.    http.send(true);
  5.    setTimeout("sndReq()", 2000); // Recursive JavaScript function calls sndReq()
  6. every 2 seconds
  7. }
  8.  
  9. function handleResponse() {
  10.    if(http.readyState == 4){
  11.       var response = http.responseText;
  12.       if (response != responseold || responsecheck != 1) {
  13.          var responsecheck = 1;
  14.          document.getElementById("messages").innerHTML = http.responseText;
  15.          var responseold = response;
  16.       }
  17.    }
  18. }
  19. </script>
  20.  
  21. </head>
  22.  
  23. <body onLoad="javascript:sndReq();">
  24. <div id="messages"></div>
  25.  
  26.  
Am I missing something simple ?

Thanks,

PT
Sep 26 '07 #9
dmjpro
2,476 2GB
Good :-)
Where is this line?
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("lineCanvas").iinerHTML = http.responseText
Kind regards,
Dmjpro.
You are executing JavaScript in the Div area.
I think it will not work.
And Paulie tell me one thing why do u need to load a static page using Ajax.
Does the page change?
If some changes in your Graph then get the updated data from data base in XML format then draw the graph here.
You got my point?
:-)

Kind regards,
Dmjpro.
Sep 26 '07 #10
paulie
6
You are executing JavaScript in the Div area.
I think it will not work.
And Paulie tell me one thing why do u need to load a static page using Ajax.
Does the page change?
If some changes in your Graph then get the updated data from data base in XML format then draw the graph here.
You got my point?
:-)

Kind regards,
Dmjpro.
Howdy,

The page does change. It is updated via a perl script. I will certainly give the xml method a go and see if this works.

Thanks for your time and help!

Have a good day.
Sep 27 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Joel Byrd | last post by:
I want a website that works in the following way: It has a main content div, and of course menu items. When you click a menu item, it should use AJAX to change the main content div to the content...
4
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
8
by: Samik R. | last post by:
Hello, I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I...
1
by: bsprogs | last post by:
I am currnetly programming a file hosting website in PHP and I am slowly integrating AJAX into the website. Here is my problem: The user uploads the file. The server processes the file and...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
6
by: John Doe | last post by:
Here's my issue: I have an instant messenger type feature for my site, its basically an ajax IM feature. I run with a mysql backend on the site, i have a div on my main page that runs a javascript...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.