Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wczytywanie zdjęć bez przeładowania strony
pirates21
post
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 4.08.2011

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


Witam.
Chcę aby po kliknięciu zdjęcia miniaturki załadował się większy obrazek. Chcę to zrobić przy pomocy ajaxowej funkcji getdata(). Problem w tym, zę po kliknięciu w miniaturkę ukazują się tzw. "krzaki" zamiast zdjęcia. Jak to wykonać poprawnie?

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
  3. <head>
  4. <title>jCarousel Examples
  5. </title>
  6. <!--
  7. Ajax - getdata();
  8. -->
  9. <script type="text/javascript" src="../lib/ajax.js"></script>
  10. </head>
  11. <body>
  12. <div id="wrap">
  13. <div id="imagePane>
  14. </div>
  15. <a href="#" onclick="getdata('../obrazki/1.jpg','imagePane');">
  16. <img src="../miniaturki/thumb_1.jpg"></a>
  17. </div>
  18. </body>
  19. </html>


  1.  
  2. // here we define global variable
  3. var ajaxdestination="";
  4.  
  5. function getdata(what,where) { // get data from source (what)
  6. try {
  7. xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  8. new ActiveXObject("Microsoft.XMLHTTP");
  9. }
  10. catch (e) { /* do nothing */ }
  11.  
  12. document.getElementById(where).innerHTML ="<center><img src='loading.gif'></center>";
  13. // we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
  14. ajaxdestination=where;
  15. xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
  16. xmlhttp.open("GET", what);
  17. xmlhttp.send(null);
  18. return false;
  19. }
  20.  
  21. function triggered() { // put data returned by requested URL to selected DIV
  22. if (xmlhttp.readyState == 4) if (xmlhttp.status == 200)
  23. document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
  24. }


Ten post edytował pirates21 4.08.2011, 13:42:47
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: 22.08.2025 - 16:00