简体   繁体   中英

Nesting Ajax calls in Prototype

I need to make two Ajax calls, one dependent on the return value of the previous call. I've attempted to create a new Ajax object from within the onComplete function of the outer object, however it seems that this never gets called.

The onComplete function of the outer object is being called. Code is executed up to where I construct the second Ajax object.

It looks something like this:

function called_from_page() {
  new Ajax.Request(
    '/request_url',
    { method: 'post', parameters: '', onComplete: function(originalRequest) {
      if (originalRequest.responseText == '0') {
         // do something
      } else {
         call_next_ajax();
      }
    }});
 }

 function call_next_ajax() {
    new Ajax.Request(
       '/next_request_url',
       { method: 'post', parameters: '', onComplete: some_other_function });
  }

So, the problem is, that call_next_ajax is being called, but the ajax request within it is not being called.

The only problem I can think of is: there is no 'next_request_url' or there is no 'some_other_function'. In both cases 'call_next_ajax()' will not execute.

Defer the second step by changing...

call_next_ajax();

...to...

call_next_ajax.defer();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM