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.Req开发者_开发技巧uest(
'/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();
精彩评论