Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php/AJAX] aktualny czas
hhg
post
Post #1





Grupa: Zarejestrowani
Postów: 316
Pomógł: 0
Dołączył: 5.07.2006

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


dzisiaj zaczalem sie wreszcie uczyc AJAXa ale jak zwykle paczatki sa ciezkie party.gif

dlaczego ten kod zamiast czasu pokazuje Error! ?


  1. <title>Ajax Tutorial For Newbie</title>
  2. .displaybox {
  3. width:150px;
  4. background-color:#ffffff;
  5. border:2px solid #000000;
  6. padding:10px;
  7. font:24px normal verdana, helvetica, arial, sans-serif;
  8. }
  9. <script language="JavaScript" type="text/javascript">
  10. function getXMLHTTPRequest() {
  11. try {
  12. req = new XMLHttpRequest();
  13. } catch(err1) {
  14. try {
  15. req = new ActiveXObject("Msxml2.XMLHTTP");
  16. } catch (err2) {
  17. try {
  18. req = new ActiveXObject("Microsoft.XMLHTTP");
  19. } catch (err3) {
  20. req = false;
  21. }
  22. }
  23. }
  24. return req;
  25. }
  26.  
  27. var http = getXMLHTTPRequest();
  28.  
  29. function getServerTime() {
  30. var myurl = 'gettime.php';
  31. myRand = parseInt(Math.random()*999999999999999);
  32. var modurl = myurl+"?rand="+myRand;
  33. http.open("GET", modurl, true);
  34. http.onreadystatechange = useHttpResponse;
  35. http.send(null);
  36. }
  37.  
  38. function useHttpResponse() {
  39. if (http.readyState == 4) {
  40. if(http.status == 200) {
  41. var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
  42. document.getElementById('showtime').innerHTML = timeValue.childNodes[0].nodeValue;
  43. }
  44. } else {
  45. document.getElementById('showtime').innerHTML = 'Error!';
  46. }
  47. }
  48. <meta name="generator" content="Namo WebEditor">
  49. <meta name="author" content="OnAjax.net">
  50. </head>
  51. <body onLoad="getServerTime();" bgcolor="white">
  52.  
  53. <h6>Getting the server time without page refresh</h6>
  54.  
  55. <input type="button" value="Refresh" onClick="getServerTime()">
  56. </form>
  57. <div id="showtime" class="displaybox">
  58.  
  59. <?php
  60. header('Content-Type: text/xml');
  61. echo "<?xml version=\"1.0\" ?><clock1><timenow>\" .date('H:i:s').\"</timenow></clock1></xml>";
  62. ?>
  63.  
  64. </div>
  65. </body>
  66. </html>
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 19.08.2025 - 14:52