Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> AJAX OnSuccess return PROBLEM
pfirlej
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 9.06.2007

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


Hej,

mam taki skrypt

  1. var resp = 0;
  2. function ajax() {
  3. new Ajax.Request('checkforcall.php?agent=<? echo $_SESSION['agent'] ?>', {
  4. method:'get',
  5. onComplete: function(t) {
  6. var resp = t.responseText;
  7. return resp;
  8. },
  9. });
  10. }
  11. var i = 0;
  12. while(i < 1000) {
  13. var resp = ajax()
  14. alert(resp);
  15. if(resp == '0' || resp == '1') {
  16. progress.style.display="";
  17. } else {
  18. new Insertion.After('details', resp);
  19. progress.style.display="none";
  20. buttons.style.display="";
  21. break;
  22. }
  23. i++;
  24. }


Czyli co ma sie odbyc?
chce zeby

  1. var resp = ajax()


Pobralo wartosc z

  1. onComplete: function(t) {
  2. var resp = t.responseText;
  3. return resp;
  4. },


Tymczasem zamiast dostac nowa wartosc, dostaje resp = 'undefined', nie umiem wyjac zmiennej z OnComplete i przekazac jej w inne miejsce czy to w ogole jest mozliwe?

Pozdrawiam,
Piotrek
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
fridek
post
Post #2





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 19.12.2006

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


A czemu robisz trzy razy var?
Nie jestem specem od JS, ale wg mnie wystarczy:

  1. var resp = false;
  2.  
  3. function ajax() {
  4. new Ajax.Request('checkforcall.php?agent=<? echo $_SESSION['agent'] ?>', {
  5. method:'get',
  6. onComplete: function(t) {
  7. resp = t.responseText;
  8. },
  9. });
  10. }
  11. var i = 0;
  12. while(i < 1000) {
  13. ajax;
  14. alert(resp);
  15. if(resp == '0' || resp == '1') {
  16. progress.style.display="";
  17. } else {
  18. new Insertion.After('details', resp);
  19. progress.style.display="none";
  20. buttons.style.display="";
  21. break;
  22. }
  23. i++;
  24. }
Go to the top of the page
+Quote Post
pfirlej
post
Post #3





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 9.06.2007

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


Cytat(fridek @ 9.06.2007, 16:21:34 ) *
A czemu robisz trzy razy var?
Nie jestem specem od JS, ale wg mnie wystarczy:


No i wlasnie rzecz w tym ze nie wystarczy, mimo, ze stworzyles na poczatku zmienna globalna resp, to AJAX nie nadpisuje tej zmiennej... alert => 'false'... (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
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: 25.12.2025 - 20:41