score:1
Accepted answer
So ended up solving it.
I had to actually add a
console.log()
for the "All Complete" output.... yeah...Promises were not being added to the promise array before the
$.when()
was run. I moved it into a.then()
chained to the.getJSON()
.It seemed the
group()
function was resolving before it actually was. I had to set the deferred object to the changed one (d = d.then()
), as well as encase the inside of the.then()
in a function.indexedDB.deleteDatabase("_pouch_test"); db = new PouchDB('test'); function item(limit){ var promises = []; var url = ""; //url to respond with up to limit responces var j = $.getJSON(url) .fail(function( jqxhr, textStatus, error ) { var err = textStatus + ", " + error; console.log( "Request Failed: " + err ); }) .then(function(data){ var promises=[] $.each(data.items,function(i, item){ promises.push( db.post({item:"test"}).then(console.log("Item Finished ")) ); }); return $.when.apply($,promises) }).then(function(){ console.log("Group Complete") }) return j; } function group(times){ var d = $.Deferred().resolve() for( var i=0; i<times; i++){ d = d.then(function(){return item(10)} ) } return d.promise() } function init(){ group(3).done(function(){console.log("All Complete")}) }
This outputs the following, which is as intended. Yay!
(10)Item Finished
Group Finished
(10)Item Finished
Group Finished
(10)Item Finished
Group Finished
All Complete
Related Query
- validate multiple radio button groups using jquery validator
- Waiting for multiple asynchronous JSON queries to finish before running code
- Multiple jsonp Ajax Call with jQuery deferred method $.when
- Multiple copies of timer programs inserted by AJAX: how to assure that only one copy is running
- Is it possible to make multiple calls using Jsonp with deferred objects?
- Validate multiple radio groups before form submit
- Change classes of multiple hyperlinks OnClick in a group. Multiple groups on page
- jQuery: Running multiple datepicker's on dynamically created inputs
- Running Multiple versions of jQuery at the same time
- Disable checkboxes when 6 are checked -- multiple forms on page with checkbox groups
- How to allow a POST request to proceed, while running multiple GET requests in the background?
- Running the same JS function on multiple <input> name values
- Running multiple horizontals scrolls on one page
- Deferred promise based multiple file upload handling with javascript in a for loop to an esp32 with ajax
- How do I assign the same Javascript code to multiple divs without running it at the same time
- How can I prevent a function from running more than once when multiple change events are fired at once?
- avoid ajax running twice with multiple selectors
- jQuery : Wrap separate sets of <ul></ul> tags around multiple groups of list items <li></li>
- How to fix: Ajax - Post request running multiple times
- Combining values from multiple radio groups to show a div
- jquery is running multiple times
- Scroll to the bottom of the page with offset - function running multiple times
- Deferred objects with multiple getJSON calls that depend on each other
- jQuery Bind 'Change' to Range of Fields in Multiple Groups
- JS - Getting alert multiple times while long polling on success?
- jQuery select option show / hide for multiple elements
- Execute function depending on multiple ajax calls status
- Iterate through children of multiple set of elements (class) simultaneously
- How to check status of Django generated multiple checkbox?
- XDomainRequest onload not running
- Changing contents of multiple divs depending on scroll position
- conditional statement seems to be storing multiple values for the same variable.. scoping error?
- Multiple Row JQuery Dialog Issue
- Jquery chosen multiple selections trouble
- Multiple grid header have to set using JavaScript and jQuery
- Strange occurrences with controlling multiple keys being held down
- send a multiple serialize form
- jQuery .get function sending request multiple times
- Multiple elastislide viewers on single page
- How to style multiple appended checkboxes with labels
- Multiple instances of flexslider without setting IDs - can't use flexslider api
- JQuery multiple flip panels with
- jQuery - Ajax call goes multiple times
- JQuery Plugin Pattern - Code Organization for multiple scripts
- Google Maps won't work when using classes to select multiple canvases
- JQuery append - multiple instances after removal
- how to return a deferred object on a phonegap class using jquery?
- jQuery to sequentially apply CSS styles
- Send multiple arrays and a string using json from ajax to php and receiving them on php
- jQuery multiple json requests into an array
More Query from same tag
- Calling window.close in IE throws null or object not found error
- How do I add elements to the DOM and then refer to those added elements in Javascript/JQuery?
- I am trying to display a value from an AJAX call in html using flask
- How to populate an array with HTML elements
- Recursive JSON Handlebars
- How do I add a jQuery script to WordPress?
- jquery multi level menu
- Js convert string to correct price format
- Laravel Livewire: Jquery doesn't work in a livewire component
- jQuery Coda Slider
- How to receive ajax json data in a codeigniter controller
- Dependency dropdown from database in Laravel
- How to create a local database using JSON and JavaScript for webapp
- how to add class on body if owl first item active and remove class if last item is active?
- JQuery do X when scroll reaches an anchor, accurate when resizing
- Filtering links/contents in multiple divs on click event
- On button click- do a redirect and ajax post submit form of new page, with data passed from click
- How to set default value for input with type of date in jquery repeater?
- how can i find the tr with specific id and these ids comming from database dynamically...?
- Iām in the middle of creating a quiz but some parts have me scratching my head
- jQuery UI: Sorting TRs in a tbody sometimes fails because of too little space
- ReferenceError: $ is not defined strange
- How to use my own button for "next" and "previous" instead button generated on runtime?
- Create dynamic download html link in cakephp 2.x with jquery
- PHP doesn't receive ajax post data
- Getting the values of the select option with javascript
- Re-sizing the webpage content
- Calculator: Get total sum from single input
- laravel ajax unexpected end of json input
- How to esacpe JavaScript within jQuery variable?