简体   繁体   English

在 Prototype 中嵌套 Ajax 调用

[英]Nesting Ajax calls in Prototype

I need to make two Ajax calls, one dependent on the return value of the previous call.我需要进行两个 Ajax 调用,一个取决于前一个调用的返回值。 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.我试图从外部 ZA8CFDE63311BD59EB266ZB6F 的 onComplete function 中创建一个新的 Ajax object

The onComplete function of the outer object is being called.正在调用外部 object 的 onComplete function。 Code is executed up to where I construct the second Ajax object.代码执行到我构造第二个 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.所以,问题是,call_next_ajax 被调用了,但是其中的 ajax 请求没有被调用。

The only problem I can think of is: there is no 'next_request_url' or there is no 'some_other_function'.我能想到的唯一问题是:没有'next_request_url'或没有'some_other_function'。 In both cases 'call_next_ajax()' will not execute.在这两种情况下,'call_next_ajax()' 都不会执行。

Defer the second step by changing...通过更改来推迟第二步...

call_next_ajax();

...to... ...至...

call_next_ajax.defer();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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