Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][PHP]Kilka odświeżaczy divów
koxu1996
post
Post #1





Grupa: Zarejestrowani
Postów: 139
Pomógł: 3
Dołączył: 5.06.2011

Ostrzeżenie: (0%)
-----


Witam. Mam na stronie diva który się odświeża i pokazuje logi. Chciałem zrobić jeszcze dynamiczny div pokazujący liczbę pozostałych punktów. Jednak po dodaniu drugiego takiego "odświerzacza" na stronie oba przestały działać :/

Jak użyć kilku poniższych skryptów aby działały?

KOD
index.php
  1. <script src="ajax.js"></script>
  2. <strong>Logi</strong>
  3. <script type="text/javascript"><!--
  4. refreshdiv();
  5. // --></script>
  6. <div id="timediv"></div>


ajax.js
  1. // Customise those settings
  2.  
  3. var seconds = 1;
  4. var divid = "timediv";
  5. var url = "boo.php";
  6.  
  7. ////////////////////////////////
  8. //
  9. // Refreshing the DIV
  10. //
  11. ////////////////////////////////
  12.  
  13. function refreshdiv(){
  14.  
  15. // The XMLHttpRequest object
  16.  
  17. var xmlHttp;
  18. try{
  19. xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
  20. }
  21. catch (e){
  22. try{
  23. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
  24. }
  25. catch (e){
  26. try{
  27. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  28. }
  29. catch (e){
  30. alert("Your browser does not support AJAX.");
  31. return false;
  32. }
  33. }
  34. }
  35.  
  36. // Timestamp for preventing IE caching the GET request
  37.  
  38. fetch_unix_timestamp = function()
  39. {
  40. return parseInt(new Date().getTime().toString().substring(0, 10))
  41. }
  42.  
  43. var timestamp = fetch_unix_timestamp();
  44. var nocacheurl = url+"?t="+timestamp;
  45.  
  46. // The code...
  47.  
  48. xmlHttp.onreadystatechange=function(){
  49. if(xmlHttp.readyState==4){
  50. document.getElementById(divid).innerHTML=xmlHttp.responseText;
  51. setTimeout('refreshdiv()',seconds*1000);
  52. }
  53. }
  54. xmlHttp.open("GET",nocacheurl,true);
  55. xmlHttp.send(null);
  56. }
  57.  
  58. // Start the refreshing process
  59.  
  60. var seconds;
  61. window.onload = function startrefresh(){
  62. //setTimeout('refreshdiv()',seconds*1000);
  63. setTimeout('refreshdiv()',seconds*500);
  64. }


boo.php
  1. <?php
  2.  
  3. // Configure connection settings
  4. $host="xxxxxx"; // Nazwa hosta.
  5. $db = 'xxxxxx';
  6. $db_admin = 'xxxxx';
  7. $db_password = 'xxxxxxx';
  8. $tablename = 'test';
  9.  
  10.  
  11.  
  12. // Title
  13.  
  14. //echo "Contents of the table:";
  15.  
  16. // Connect to DB
  17.  
  18. $sql = mysql_connect($host, $db_admin, $db_password)
  19.  
  20. mysql_select_db("$db", $sql);
  21.  
  22. // Fetch the data
  23.  
  24. //$query = "SELECT * FROM $tablename ORDER BY id DESC";
  25. ///$query = "SELECT * FROM $tablename";
  26. //$result = mysql_query($query);
  27.  
  28. // Return the results, loop through them and echo
  29. $result = mysql_query("SELECT * FROM $tablename ORDER BY id DESC LIMIT 8",$sql)
  30. or die ("nie wykonalem");
  31.  
  32. while ($roww = mysql_fetch_row($result)) {
  33. echo ' '.$roww[1].' '.$roww[2].' '.$roww[3].' '.$roww[4] .'<br>' ;
  34. }
  35.  
  36. ?>


Może lepiej to będzie zrobić w jQuery?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.09.2025 - 18:03