Witam

Widzialem na forum podobne watki, ale cos u mnie nie dziala tak jka byc tego chcial.

Mam nastepujace skrypty:

index.php
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>TEST</title>
  6. <script language="JavaScript" type="text/javascript" src="ajax.js"></script>
  7. </head>
  8. <body onload="ajax_update();">
  9. <?php
  10. echo "<div id='content'>Loading</div>\n";
  11. ?>
  12. </body>
  13. </html>



ajax.js
  1. var xmlhttp = false ;
  2.  
  3.  
  4. if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
  5. {
  6. try {
  7. xmlhttp = new XMLHttpRequest ();
  8. }
  9. catch (e) {
  10. xmlhttp = false}
  11. }
  12.  
  13.  
  14. function myXMLHttpRequest ()
  15. {
  16. var xmlhttplocal;
  17. try {
  18. xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
  19. catch (e) {
  20. try {
  21. xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
  22. catch (E) {
  23. xmlhttplocal = false;
  24. }
  25. }
  26.  
  27. if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
  28. try {
  29. var xmlhttplocal = new XMLHttpRequest ();
  30. }
  31. catch (e) {
  32. var xmlhttplocal = false;
  33. }
  34. }
  35. return (xmlhttplocal);
  36. }
  37.  
  38.  
  39. var mnmxmlhttp = Array ();
  40. var mnmString = Array ();
  41. var mnmPrevColor = Array ();
  42. var responsestring = Array ();
  43. var myxmlhttp = Array ();
  44. var responseString = new String;
  45.  
  46.  
  47. var i=0;
  48. var ii = 0;
  49.  
  50. function ajax_update()
  51. {
  52.  
  53. url = "graph.php";
  54. //url = "demo/DirectPNGOutputTest.php"
  55. target2 = document.getElementById ('content');
  56.  
  57. ii = i++;
  58.  
  59. var content = "i=" + ii ;
  60.  
  61. mnmxmlhttp = new myXMLHttpRequest ();
  62. if (mnmxmlhttp) {
  63. mnmxmlhttp.open ("POST", url, true);
  64. mnmxmlhttp.setRequestHeader ('Content-Type',
  65. 'application/x-www-form-urlencoded');
  66.  
  67. mnmxmlhttp.send (content);
  68. errormatch = new RegExp ("^ERROR:");
  69.  
  70. target2 = document.getElementById ('content');
  71.  
  72. mnmxmlhttp.onreadystatechange = function () {
  73. if (mnmxmlhttp.readyState == 4) {
  74. mnmString = mnmxmlhttp.responseText;
  75.  
  76. if (mnmString.match (errormatch)) {
  77. mnmString = mnmString.substring (6, mnmString.length);
  78.  
  79. target = document.getElementById ('content');
  80. //target2.innerHTML = mnmString;
  81. target2.innerHTML = '<img border="0" src="graph.php">';
  82.  
  83. } else {
  84. target = document.getElementById ('content');
  85. //target2.innerHTML = mnmString;
  86. target2.innerHTML = '<img border="0" src="graph.php">';
  87.  
  88. }
  89. }
  90. }
  91. }
  92.  
  93.  
  94. setTimeout('ajax_update()', 1000);
  95.  
  96. }




graph.php
  1. <?php
  2.  
  3. /*
  4.  
  5.  Code written by Adam Crownoble adam@obleDesign.com
  6.  
  7.  You may take this code this code and change it
  8.  however you like. My only request is that keep
  9.  this comment in place and comment your own
  10.  changes. Happy coding.
  11.  
  12.  This code dynamically renders a thermostat as an
  13.  image. It is meant to be used to gauge donations to
  14.  a project.
  15.  
  16.  */
  17.  
  18. // Get variables
  19. $goal = $_GET['goal'];
  20. $progress = $_GET['progress'];
  21. if($progress && $goal) { $temp = $progress / $goal; }
  22.  
  23. // Image dimensions
  24. if(!$w = $_GET['w']) { $w = 45; }
  25. if(!$h = $_GET['h']) { $h = 150; }
  26.  
  27. // Border
  28. $border_w = 1;
  29.  
  30. // Tube Dimensions
  31. $tube_w_ratio = .6;
  32. $tube_w = $w * $tube_w_ratio;
  33. $tube_h = $h - ($w);
  34. $tube_l = ($w - $tube_w) / 2;
  35. $tube_r = $w - $tube_l;
  36.  
  37. // Ball Dimensions
  38. $ball_w = $w;
  39. $ball_cnt_x = $ball_w / 2;
  40. $ball_cnt_y = $h - ($ball_cnt_x);
  41.  
  42. // Marks
  43. $mark_num = 10;
  44. $mark_w_min_ratio = .15;
  45. $mark_w_max_ratio = .3;
  46. $mark_w_min = $tube_w * $mark_w_min_ratio;
  47. $mark_w_max = $tube_w * $mark_w_max_ratio;
  48. $mark_spacing = $tube_h / $mark_num;
  49.  
  50. // Image
  51. $img = imagecreatetruecolor($w,$h);
  52.  
  53. // Settings
  54. imageantialias($img,true);
  55. imagesetthickness($img,$border_w);
  56.  
  57. // Colors
  58. $black = imagecolorallocate($img,100,100,100);
  59. $white = imagecolorallocate($img,255,255,255);
  60. $gray = imagecolorallocate($img,225,225,225);
  61. $red = imagecolorallocate($img,190,0,0);
  62.  
  63. // Background
  64. imagefilledrectangle($img,0,0,$w,$h,$white);
  65.  
  66. // Draw Tube
  67. imagefilledrectangle($img,
  68.                      $tube_l,
  69.                      0,
  70.                      $tube_r,
  71.                      $tube_h,
  72.                      $gray);
  73. // Top
  74. imageline($img,
  75.           $tube_l,
  76.           0,
  77.           $tube_r,
  78.           0,
  79.           $black);
  80. // Left
  81. imageline($img,
  82.           $tube_l,
  83.           0,
  84.           $tube_l,
  85.           $tube_h + ($ball_w / 2),
  86.           $black);
  87. // Right
  88. imageline($img,
  89.           $tube_r,
  90.           0,
  91.           $tube_r,
  92.           $tube_h + ($ball_w / 2),
  93.           $black);
  94.  
  95. // Draw Ball
  96. imagefilledellipse($img,
  97.                    $ball_cnt_x,
  98.                    $ball_cnt_y,
  99.                    $ball_w,
  100.                    $ball_w,
  101.                    $red);
  102. imageellipse($img,
  103.              $ball_cnt_x,
  104.              $ball_cnt_y,
  105.              $ball_w,
  106.              $ball_w,
  107.              $black);
  108.  
  109. // Draw Mercury
  110. imagefilledrectangle($img,
  111.                      $tube_l + $border_w,
  112.                      $tube_h - ($tube_h * $temp),
  113.                      $tube_r - $border_w,
  114.                      $tube_h + ($ball_w / 2)
  115.                              + $border_w,
  116.                      $red);
  117.  
  118. // Draw Marks
  119. for($i = 1; $i <= $mark_num; $i++) {
  120.  
  121.  if(1&$i) {
  122.   $mark_w = $mark_w_min;
  123.  } else {
  124.   $mark_w = $mark_w_max;
  125.  }
  126.  
  127.  imageline($img,
  128.            $tube_l,
  129.            $mark_spacing * $i,$tube_l + $mark_w,
  130.            $mark_spacing * $i,
  131.            $black);
  132. }
  133.  
  134. // Set the content type to PNG
  135. header("Content-type: image/png");
  136.  
  137. // Output the image
  138. imagepng($img);
  139.  
  140. // Clear up the resources
  141. imagedestroy($img);
  142.  
  143. ?>


Wszystko niby smiga, obrazek niby sie odswieza, ale zmiany parametrow w pliku graph.php nie sa widoczne.
Sytuacja wyglada tak, jak gdyby AJAX nie odsieżał pliku graph.php lub nie potrafil pretworzyc grafiki.


Pozdrawiam wszystkich

// Następnym razem patrz jakie bbcode dodajesz.
// Tag manual na pewno nie jest dla JasvaScript.
// ~webdice