有没有办法判断最后一个ajax调用是否完成?
我正在处理这个网站,我需要弄清楚最后一次是什么时候ajax 调用完成...我正在使用这个 jQuery 插件,一切都很好,但是问题是客户端一次上传 2 个文件...并且我需要在最后一次 ajax 调用后重定向到另一个页面。如果您在上传文件时在 firebug 中查看它,它会运行 http://dev.posnation.com/test/j/example/upload.php
两次,并且我需要在且仅此后进行页面重定向第二次运行后..javascript 或 jQuery 是否有方法来判断 ajax 调用是否完成。
这是实例化它的代码
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();
,并且 jQuery.fileupload.js 中有一个 onDone 函数,
_onDone: function (result, textStatus, jqXHR, options) {
但它在第一次运行后运行,而不是在两个文件上传后运行....有关如何在两个文件上传后重定向到另一个页面的任何想法已上传....提前致谢
I have this site that i am working on that i need to figure out when the last ajax call is finished...I am using this jQuery plugin and all works great but the problem is the client uploads 2 files at a time... and i need to redirect to another page after the last ajax call. If you look the it in firebug while uploading files it run http://dev.posnation.com/test/j/example/upload.php
twice and i need to have the page redirect after and only after the second run..is there a way in javascript or jQuery to tell if the ajax calls are complete.
Here is the code that instantiates it
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();
and there is a onDone function in the jQuery.fileupload.js
_onDone: function (result, textStatus, jqXHR, options) {
but its running after the first run not after both files are uploaded....any ideas on how i can redirect to another page after both files are uploaded....thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的答案是减少 onDone 回调中的计数器。一种可能的实现是使用全局变量,如下所示:
还有更优雅的解决方案,但它们都涉及递减计数器。
the short answer is to decrement a counter in the onDone callback. one possible implementation would be to use a global variable as illustrated below:
there are more elegant solutions, but they will all involve decrementing a counter.
您可以使用 closure 来生成具有已上传文件的本地记录的函数。
fileUploads 将在上传 2 个文件后触发回调函数。回调和文件限制在此行中指定
You could use closure to produce the function which has a local records for files have uploaded.
fileUploads will fire the
callback
function after 2 files are uploaded. The callback and filelimits are specified in this line