Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> JQuery - obsłużenie odpowiedzi rządania Ajax
adas007
post 30.09.2010, 12:20:20
Post #1





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 9.03.2007

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


Witam. Czemu nie działa mi poniższy przykład?

Używając JQuery napisałem funkcję, która ma przesłać do skryptu removeFile.php zmienną "nazwa" a potem zapisać odpowiedź serwera do elementu div, który ma id "test".
  1. $("#remove").click(function()
  2.  
  3. {
  4.  
  5. $.ajax(
  6.  
  7. {
  8.  
  9. type:'Post',
  10. url:'removeFile.php',
  11. data:'nazwa=kurka',
  12. succes: function(data)
  13. {
  14. $('#test').html(data);
  15. }
  16.  
  17. }
  18. );
  19.  
  20.  
  21. }
  22.  
  23. );



W pliku removeFile.php mam coś takiego:
  1. <?php
  2. $names=$_POST['nazwa'];
  3. echo "<h1>$names</h1>";
  4. ?>


Odpowiedź serwera nie wyświetla się w elemencie <div id='test'></div>
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 12:25:15
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




nie: Post
a: POST


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
adas007
post 30.09.2010, 12:30:47
Post #3





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 9.03.2007

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


Poprawiłem to, ale wciąż odpowiedź serwera się nie wyświetla.
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 12:33:28
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




zainstaluj sobie FireBuga dla FireFox i zobacz co ten Twoj ajax robi a bedzie wszystko jasne.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
adas007
post 30.09.2010, 12:45:02
Post #5





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 9.03.2007

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


Oto co mówi firebug:

Zakładka Post:

Parametry application/x-www-form-urlencoded
nazwa kurka
Źródło
nazwa=kurka

Zakładka Odpowiedź:

<h1>kurka</h1>

Zakładka HTML:

kurka
Zakładka Nagłówki:
Nagłówki odpowiedzi:
Date Thu, 30 Sep 2010 11:39:18 GMT
Server Apache/2.2.8 (Win32) PHP/5.2.6
X-Powered-By PHP/5.2.6
Content-Length 18
Keep-Alive timeout=5, max=98
Connection Keep-Alive
Content-Type text/html

Nagłówki zapytania:
Host localhost
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
Accept */*
Accept-Language pl,en-us;q=0.7,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-2,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer http://localhost/rdf2/index.php
Content-Length 11
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 13:01:40
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Czyli AJAX dziala.
Kod
       succes: function(data)
        {
alert('widzisz mnie?');
        $('#test').html(data);
        }

Dostales alerta?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
adas007
post 30.09.2010, 13:06:13
Post #7





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 9.03.2007

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


Alert się nie pokazuje.
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 13:10:08
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




No i masz winowajce. nie mozna bylo tak od razu samemu sprawdzic? winksmiley.jpg

dodaje jeszcze
dataType:'html'


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
adas007
post 30.09.2010, 13:15:28
Post #9





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 9.03.2007

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


  1. url:'removeFile.php',
  2. data:'nazwa=kurka',
  3. dataType:'html',
  4. succes: function(data){
  5. alert('widzisz mnie?');
  6. $('#test').html(data);


Dodałem tutaj nie wiem czy o to chodziło, bo wciąż nie działa.
Go to the top of the page
+Quote Post
nospor
post 30.09.2010, 13:16:33
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




nie: succes
a: success
winksmiley.jpg


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
adas007
post 30.09.2010, 13:18:38
Post #11





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 9.03.2007

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


Działa ! Dziękuję bardzo smile.gif
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: 14.08.2025 - 01:08