How do I use jQuery 'queue' to delay action until series of AJAX events have completed?
enter code here
I have the following code to build select menus dynamically:
$j("#id").load('create_menu.cgi', 'view=select_menu');
The same menu is used on multiple parts of the page, so rather sending requests over and over to create_menu.cgi, I want to copy from the first one created to the other spots on the开发者_JAVA百科 page needing the menu.
I have used 'queue' in the past for some things and thought I could use it here. However, it seems like queue in this case will just run once the URL (create_menu.cgi) is called not necessarily after the menu is place in the field. So for example the following is not working:
$j("#id").load('create_menu.cgi', 'view=select_menu').queue(function(){
doSomething();
$j(this).dequeue;
});
doSomething() does not wait until the menu is actually there. Is there a way to use 'queue' for something like this so the menu is copied to the another element on the page immediately following the creation of the first one?
You can instead use the third parameter of the load
function; the complete
callback.
.load( url, [ data ], [ complete(responseText, textStatus, XMLHttpRequest) ] )
So, in your case, something like this:
$j("#id").load('create_menu.cgi', 'view=select_menu', doSomething);
Documentation.
精彩评论