admin管理员组文章数量:1402923
I have a question, I think the answer will be simple, but I can't really find it ...
I have a function that creates content with ajax. After the function is finished I want to do something with the created content. To do that, I need to wait until all content is created, before I can do something with it.
What I prefer is something like this:
viewAllAccounts(function() {
//do something
});
or
viewAllAccounts().queue(function() {
// do something
});
But offcourse this is not going to work :)
I don't want to touch the viewAllAccounts function, because it is used multiple times in my app.
Is there a simple way to do something after a function is finished, not altering the function itself?
Thanks in advance!
I have a question, I think the answer will be simple, but I can't really find it ...
I have a function that creates content with ajax. After the function is finished I want to do something with the created content. To do that, I need to wait until all content is created, before I can do something with it.
What I prefer is something like this:
viewAllAccounts(function() {
//do something
});
or
viewAllAccounts().queue(function() {
// do something
});
But offcourse this is not going to work :)
I don't want to touch the viewAllAccounts function, because it is used multiple times in my app.
Is there a simple way to do something after a function is finished, not altering the function itself?
Thanks in advance!
Share Improve this question asked Mar 1, 2011 at 14:26 Xeon43Xeon43 411 silver badge2 bronze badges 1-
adding a call to another function (that does soemthing) just before the
return ;
is called onviewAllAccounts
? – ypercubeᵀᴹ Commented Mar 1, 2011 at 14:29
3 Answers
Reset to default 3when you invoke ajax calls with jquery, there are a bunch of handlers that fire when the ajax call pletes. You should hook into those. Take a look-see at
http://api.jquery./jQuery.ajax/
particularly the 'success' and 'error' properties. just define functions for those and they will get called when the request pletes.
For if you do not want to waste hundreds of bytes and a bunch of milliseconds on jQuery*:
You can create a second function:
function viewAllAccountsWithFinishingFunction(func) {
viewAllAccounts();
return func();
}
Then call:
viewAllAccountsWithFinishingFunction(function() {
//do something
});
* I do like jQuery, but using it for just one out of hundreds of features it has, I don't find it necessary.
Check out jQuery deferred objects:
http://www.erichynds./jquery/using-deferreds-in-jquery/
http://api.jquery./category/deferred-object/
本文标签: javascriptDo something after function is finishedStack Overflow
版权声明:本文标题:javascript - Do something after function is finished - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744375867a2603257.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论