Witam. Chciałem zrobić stronę, która po wciśnięciu jakiegoś linka z menu wczyta jakiś dokument bez przeładowania całego dokumentu. Użyłem w tym celu AJAX'a, lecz nie mam pojęciu czemu skrypt, który napisałem nie działa:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl" dir="ltr">
  3. <head>
  4. <title>Moja pierwsza strona w XHTML</title>
  5. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
  6. <meta http-equiv="Content-Language" content="pl"/>
  7.  
  8. <style type="text/css">
  9. #container
  10. {
  11. width: 804px;
  12. height: 600px;
  13. margin: 1em auto;
  14. border: 1px solid red;
  15. overflow: hidden;
  16. }
  17. #menu
  18. {
  19. float: left;
  20. width: 300px;
  21. border: 1px solid red;
  22. height: 600px;
  23. }
  24.  
  25. #content
  26. {
  27. float: right;
  28. width: 500px;
  29. height: 600px;
  30. border: 1px solid red;
  31. }
  32.  
  33. </style>
  34.  
  35. <script type="text/javascript">
  36. var r;
  37. var e;
  38.  
  39. function onClickFunction(link,id)
  40. {
  41. if (r = getXMLHttpRequest()) {
  42. e = document.getElementById(id);
  43. r = new HMLHttpRequest();
  44. r.open('GET',link);
  45. r.onreadystatechange = odbierzDane;
  46. r.send(null);
  47. }
  48. }
  49.  
  50. function odbierzDane()
  51. {
  52. if(r.readyState == 4){
  53. if(r.status == 200 || r.status == 304){
  54. e.innerHTML = r.responseText;
  55. }
  56. }
  57. }
  58. </script>
  59.  
  60. </head>
  61. <body>
  62. <div id="container">
  63.  
  64. <div id="menu">
  65. <ul>
  66. <li><a onclick="onClickFunction('text.xhtml','content');" href="#">Link1</a></li>
  67. <li><a onclick="onClickFunction" href="#">Link2</a></li>
  68. </ul>
  69. </div>
  70.  
  71. <div id="content">
  72.  
  73. </div>
  74.  
  75. </div>
  76. </body>
  77. </html>


Dokument, który ma się wczytać to:
  1. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  2.  
  3. <p>Jakis text</p>



Proszę o pomoc.

Nie odpowiadajcie, dopiero się kapnąłem, że jest dział AJAX. Proszę o usunięcie tego tematu.