Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> 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
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
Morkai
post
Post #4





Grupa: Zarejestrowani
Postów: 24
Pomógł: 3
Dołączył: 25.08.2005

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


Mógłbyś podać, że korzystasz z biblioteki Prototype (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Kod
var handleCheckForAll = function( transport )
{
    var result = transport.responseText;
    
    if ( ( result == '0' ) || ( result == '1' ) )
    {
        progress.style.display = '';
    }
    else
    {
        new Insertion.After( 'details', result );
        
        progress.style.display = 'none';
        buttons.style.display  = '';
        
        i = 1000;
    }
}

for ( var i = 0; i < 1000; i++ )
{
    new Ajax.Request( 'checkforall.php',
    {
        method: 'get',
        params:
        {
            agent: '<?php print $_SESSION['agent'] ?>'
        },
        onComplete: handleCheckForAll
    } );
}


Albo zostosuj kod frideka, z tym że popraw
Kod
while(i < 1000) {
ajax;
alert(resp);
na
Kod
while(i < 1000) {
ajax();
alert(resp);


Ajax.Request() nic nie zwraca, dlatego Twój kod nie działa.

Ten post edytował Morkai 9.06.2007, 17:45:53
Go to the top of the page
+Quote Post

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 - 15:00