Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [AJAX] aktualizacja daty
bloter
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 7.05.2007

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


Witam!

Mam problem z aktualizacja daty. Po kliknieciu w przycisk nie aktualizuje sie data.
Plik time.php wywolany bezposrednio dziala prawidlowo.

Oto kody:
plik data.html
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.  
  5. <title>AJAX czas</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
  7. <script type="text/javascript">
  8. var request = false;
  9.  
  10. function retrieveDate() {
  11. request false;
  12.  
  13. if (window.XMLHttpRequest) {
  14. request = new XMLHttpRequest();
  15. } else if (window.ActiveXObject) {
  16. request = new ActiveXObject("Microsoft.XMLHTTP");
  17. }
  18.  
  19. if (!request) {
  20. alert('nie obsluguje AJAX ');
  21. return false;
  22. }
  23.  
  24. request.onreadystatechange = updateDate;
  25. request.open('GET','time.php?format=' + escape(document.myform.dformat.value),true);
  26. request.send(null);
  27. }
  28.  
  29. function updateDate() {
  30. if (request.readyState == 4) {
  31. if (request.status == 200) {
  32. var xml = request.responseXML;
  33. var result = xml.getElementsByTagName('result').item(0);
  34. var text = document.getElementById('datetext');
  35. text.innerHTML = result.firstChild.data;
  36. } else {
  37. alert('ERROR podczas realizacji żądania !!' + request.status);
  38. }
  39. }
  40. }
  41. </head>
  42.  
  43. <p>kliknij w przycisk...</p>
  44. <p id="datetext">--TUTAJ BEDZIE DATA--</p>
  45. <form id="myform" name="myform">
  46. <p>
  47. <input type="text" id="dformat" name="dformat" value="r" />
  48. <input type="button" value="Aktualizacja" onclick="retrieveDate()" />
  49. </p></form>
  50. </body>
  51. </html>



pilk time.php
  1. <?php
  2. $format = isset($_GET['format']) ? $_GET['format'] : 'r';
  3.  
  4. date_default_timezone_set('America/New_York');
  5. $dstr = date($format);
  6. header('Content-Type: text/xml');
  7. header('Cache-control: no-cache');
  8.  
  9. echo <<<EOXML
  10. <?xml version="1.0" ?>
  11. <result>{$dstr}</result>
  12. EOXML;
  13. ?>
Go to the top of the page
+Quote Post

Posty w temacie
- bloter   [AJAX] aktualizacja daty   9.01.2009, 13:40:23
- - bazyliszek83   "request = false;" zamiast "request...   2.02.2009, 15:39:34


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: 22.08.2025 - 16:56