Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [AJAX]System głosowania
pawelsz66
post 29.11.2010, 12:29:37
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 10.01.2010

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


Pokaże wam co jak na razie mam
index.php
  1. <a href="#" id="plus"><img src="plus.jpg"" id="plus" /></a>
  2. <span id="ile"> '.($glosy-1).'</span>
  3.  
  4.  
  5.  
  6.  
  7.  
  8. <a href="#" id="minus"><img src="minus.jpg" /></a> ';

script.js
  1. $(document).ready(function() {
  2.  
  3. $("#plus").unbind().bind("click", function() {
  4.  
  5. $.ajax({
  6.  
  7. type: 'POST',
  8.  
  9. url: '/glos.php',
  10.  
  11. data: 'action=plus',
  12.  
  13. success: function(wynik) {
  14.  
  15. $("#ile").html(wynik)
  16.  
  17. }
  18.  
  19. });
  20.  
  21. return false;
  22.  
  23. });
  24.  
  25.  
  26. $("#minus").unbind().bind("click", function() {
  27.  
  28. $.ajax({
  29.  
  30. type: 'POST',
  31.  
  32. url: '/glos.php',
  33.  
  34. data: 'action=minus',
  35.  
  36. success: function(wynik) {
  37.  
  38. $("#ile").html(wynik)
  39.  
  40. }
  41.  
  42. });
  43.  
  44. });
  45.  
  46. return false;
  47.  
  48. });

oraz glos.php
  1. $plus = "UPDATE przerobka SET glosy=glosy+1 WHERE p_id=1;";
  2. $minus = "UPDATE przerobka SET glosy=glosy-1 WHERE p_id=1';";
  3. $gloss = mysql_query("SELECT * FROM przerobka WHERE p_id=1;");
  4. $il = 0;
  5. if($row = mysql_fetch_assoc($gloss)) {
  6. $il = $row['glosy'];
  7. }
  8. if($_POST['action'] == 'plus') {
  9. mysql_query($plus);
  10. print $il++;
  11. } elseif($_POST['action'] == 'minus') {
  12. mysql_query($minus);
  13. print $il--;
  14. }

Wszystko działa tylko chciałbym zmienną z numerem id wysłać z index.php do glos.php.

Ten post edytował pawelsz66 29.11.2010, 19:16:15
Go to the top of the page
+Quote Post
md1988
post 29.11.2010, 12:44:13
Post #2





Grupa: Zarejestrowani
Postów: 19
Pomógł: 1
Dołączył: 27.11.2010

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


Musisz dodać tylko zmienną do wyslania POSTem ;p

  1. data: 'action=plus,id='+idDoWyslania

Jakoś tak to szło ;p
Wtedy w $_POST powinieneś dostać to co chcesz.



Ten post edytował md1988 29.11.2010, 12:45:02
Go to the top of the page
+Quote Post
pawelsz66
post 29.11.2010, 19:15:25
Post #3





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 10.01.2010

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


Kombinowałem nad tym i bez żadnych rezultatów. Co mam dać w index.php ? Wykombinowałem coś takiego:
  1. <a href="#" id="plus(' . $pid . ')"><img src="plus.jpg" id="plus(' . $pid . ')" /></a>

Oraz co wpisać w tym pliku .js ? Zmeniłem na coś takiego:
  1. $("#plus"(id)).unbind().bind("click", function() {
  2. $.ajax({
  3. type: 'POST',
  4. url: '/glos.php',
  5. data: "action=plus,id="+id,
  6. success: function(wynik) {
  7. $("#ile"(id)).html(wynik)
  8. }
  9. });
  10. return false;
  11. });
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 Wersja Lo-Fi Aktualny czas: 18.06.2025 - 19:24