Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [AJAX] Wysyłanie danych GET i zmiana zawartości diva
Siper
post
Post #1





Grupa: Zarejestrowani
Postów: 60
Pomógł: 1
Dołączył: 25.04.2009

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


Mam problem.
Chcę zrobić prosty skrypt głosowania z JavaScriptem. Od strony PHP i MySQL mam wszystko gotowe, skrypt wysyła liczbę w zależności od wyniku (-1 = Error, 0 = Udało się, 1 = Już głosowano).


Aktualnie mam:
  1. function glosuj( id, ip )
  2.  
  3. {
  4.  
  5. var oD = document.createElement( 'div' );
  6.  
  7. insertAfter( object, oD );
  8.  
  9.  
  10.  
  11. advAJAX.get({
  12.  
  13. url: "glosuj.php?id="+id+"&ip="+ip,
  14.  
  15. mimeType: 'text/html',
  16.  
  17. onSuccess : function(obj)
  18.  
  19. {
  20.  
  21. if(obj.responseText == "-1"){
  22. oD.innerHTML = "Error"
  23. }
  24. if(obj.responseText == "0"){
  25. oD.innerHTML = "Dzięki!"
  26. }
  27. if(obj.responseText == "2"){
  28. oD.innerHTML = "Już glos."
  29. }
  30. }
  31.  
  32. });
  33.  
  34. object.setAttribute( 'onclick',"" );// special 4 IE
  35.  
  36.  
  37.  
  38. }


Wiem, że niedopracowany zbytnio (np. tworzy nowego diva a nie aktualizuje), ale nie ogarniam zbytnio AJAX i większość kodu piszę "w locie". Byłbym wdzięczny gdyby się to również poprawiło smile.gif

Link mam tak:
  1. <a href="java script:void(0);" onclick="glosuj('ID', 'IP')">Głosuj</a>


Nic się nie dzieje, nie wysyła nawet info, co może być problemem?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


Zobacz w moja sygnaturę i napisz co wywali konsola

Ten post edytował CuteOne 1.09.2011, 21:18:42
Go to the top of the page
+Quote Post
Siper
post
Post #3





Grupa: Zarejestrowani
Postów: 60
Pomógł: 1
Dołączył: 25.04.2009

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


Wielkie dzięki, teraz wszystko wysyła smile.gif
Jednak nadal jest problem z aktualizacja statusu, nie mam pojęcia jak zrobić myk ze zmianą diva (można span?),

Trochę pogrzebałem i mam coś takiego:
  1. function glosuj(object, id, ip )
  2.  
  3. {
  4. advAJAX.get({
  5.  
  6. url: "glosuj.php?id="+id+"&ip="+ip,
  7.  
  8. mimeType: 'text/html',
  9.  
  10. onSuccess : function(obj)
  11.  
  12. {
  13.  
  14. if(obj.responseText == "-1"){
  15. document.getElementById("status"+id).innerHTML = "Error"
  16. }
  17. if(obj.responseText == "0"){
  18. document.getElementById("status"+id).innerHTML = "Dzięki!"
  19. }
  20. if(obj.responseText == "2"){
  21. document.getElementById("status"+id).innerHTML = "Już glos."
  22. }
  23. }
  24.  
  25. });
  26.  
  27. object.setAttribute( 'onclick',"" );// special 4 IE
  28.  
  29.  
  30.  
  31. }

Link (z kodem PHP):
  1. <span id="status'.$wynik["ID"].'"><a href="java script:void(0);" onclick="glosuj(this, \''.$wynik["ID"].'\', \''.$_SERVER['REMOTE_ADDR'].'\')">Głosuj</a></span>


Zrobiłem taki myk: Wyrzuciłem Ifa i dałem tylko jedną funkcję, zadziałało, więc pewnie warunek 'obj.responseText == "x"' jest zły, jaki powinien być?

Ten post edytował Siper 4.09.2011, 15:22:36
Go to the top of the page
+Quote Post
CuteOne
post
Post #4





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


Poczytaj o console.log() i zastosuj go na obiekcie "obj"
Go to the top of the page
+Quote Post
Siper
post
Post #5





Grupa: Zarejestrowani
Postów: 60
Pomógł: 1
Dołączył: 25.04.2009

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


Nie mam pojęcia co to może być :c
Go to the top of the page
+Quote Post
CuteOne
post
Post #6





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


console.log()
[JAVASCRIPT] pobierz, plaintext
  1. var a = 'aaaaa';
  2. console.log(a);
[JAVASCRIPT] pobierz, plaintext
Go to the top of the page
+Quote Post
Siper
post
Post #7





Grupa: Zarejestrowani
Postów: 60
Pomógł: 1
Dołączył: 25.04.2009

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


Kod
ReferenceError: obj is not defined
Go to the top of the page
+Quote Post

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: 22.08.2025 - 04:50