我需要进行两个Ajax调用,其中一个依赖于前一个调用的返回值。我试图从外部对象的onComplete函数中创建一个新的Ajax对象,但是似乎从未调用过。
正在调用外部对象的onComplete函数。代码一直执行到我构造第二个Ajax对象的地方。
它看起来像这样:
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 });
}
因此,问题是,call_next_ajax正在被调用,但其中的ajax请求没有被调用。
发布于 2011-05-27 18:21:17
我能想到的唯一问题是:没有'next_request_url‘或者没有’next_request_url_other_function‘。在这两种情况下,'call_next_ajax()‘都不会执行。
发布于 2012-03-16 22:38:01
Defer第二步,通过改变...
call_next_ajax();
...to...
call_next_ajax.defer();
https://stackoverflow.com/questions/6119940
复制相似问题