在 Prototype 中嵌套 Ajax 调用
我需要进行两个 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 请求没有被调用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的唯一问题是:没有“next_request_url”或没有“some_other_function”。在这两种情况下,“call_next_ajax()”都不会执行。
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...
...to...