1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4.  
  5.  
  6. <title>Przyklad wykorzystania AJAX'a</title>
  7.  
  8. <script language="javascript" type="text/javascript">
  9.  
  10. var url = "http://portal.pl/ajax/pobierzNazwe.php?id=";
  11.  
  12. function handleHttpResponse() {
  13.  
  14. if (http.readyState == 4) {
  15.  
  16. var xmlDocument = http.responseXML;
  17. var wynik1 = xmlDocument.getElementsByTagName('nazwa').item(0).firstChild.data;
  18. document.getElementById('podzespol').value = wynik1;
  19.  
  20.  
  21. }
  22.  
  23. }
  24. function aktualizujNazwe() {
  25.  
  26. var numerSprzetu = document.getElementById("numer").value;
  27.  
  28. http.open("GET", url + escape(numerSprzetu), true);
  29.  
  30. http.onreadystatechange = handleHttpResponse;
  31.  
  32. http.send(null);
  33.  
  34. }
  35.  
  36. function getHTTPObject() {
  37. var xmlhttp;
  38. /*@cc_on
  39. @if (@_jscript_version >= 5)
  40. try {
  41. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  42. } catch (e)
  43. { try {
  44. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  45. } catch (E) { xmlhttp = false; }
  46. } @else xmlhttp = false; @end @*/
  47. if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
  48. { try { xmlhttp = new XMLHttpRequest(); }
  49. catch (e) { xmlhttp = false; }
  50. }
  51. return xmlhttp;
  52. }
  53. var http = getHTTPObject(); // Mamy obiekt HTTP
  54.  
  55.  
  56. </head>
  57.  
  58. <?php
  59.  
  60. /**
  61. *
  62. * @version $Id$
  63. * @copyright 2006
  64. */
  65.  
  66. ?>
  67.  
  68. <form method="POST">
  69. Numer podzespolu:<input type="text" id="numer" name="numer" onblur="aktualizujNazwe();" /><br /><br />
  70. Nazwa podzespolu:<input type="text" id="podzespol" name="podzespol" />
  71. </form>
  72.  
  73.  
  74. </body>
  75. </html>


  1. <?php
  2.  
  3. /**
  4.  *
  5.  *
  6.  * @version $Id$
  7.  * @copyright 2006
  8.  */
  9.  
  10.  
  11. $idPodzespolu = $_GET['id'];
  12. if ($idPodzespolu > 10) {
  13. $nazwa = "Karta graficzna ?"; // <-------- TU BYL BLAD! brak srednika
  14. } else {
  15. $nazwa = "A chuj go wie co to jest na sprzet";
  16. }
  17. $wynik = '<?xml version="1.0" standalone="yes"?><dane><nazwa>'.$nazwa.'</nazwa></dane>';
  18. header('Content-Type: text/xml');
  19. echo $wynik;
  20. ?>


poprostu nie dziala sad.gif jak przesylam jako text to dziala bardzo dobrze, jako xml nie bardzo, zle wysylam xmla z php czy zle go odbieram ?

o Boże, ale ze mnie debil, no nic juz "naprawione", mozna skasowac, chyba ze sie komus przyda (nowicjuszowi) najprostrze z mozliwych uzycie AJAXA