Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use jQuery when function with more postJSON queries?
    primarykey
    data
    text
    <p>I have a problem at work: I have a section of installations which are dependent on servers. I want to do this: When a user deletes a server, it loops through installations collection and deletes all dependent installations. For that I use jQuery 'when' function, which is said to wait for a response from the server and then move on to 'then' function. It works flawlessly when there is only one dependent installation. A problem occurs when there are more installations, however, because it moves to the 'then' function immediately after receiving a JSON response.</p> <p>The question is: How do I make 'when' function wait for all server responses? Eg. I send out three delete requests through $.postJSON and want to move on <em>after</em> I get all three responses. If it's not possible with 'when', what should I use to make it happen? If it helps, I maintain all my entities collections with KnockoutJS. Thanks!</p> <p>EDIT: I have it like this:</p> <pre><code>$.when(DeleteDependentInstallations()) .then (function() { ... }); </code></pre> <p>DeleteDependentInstallations looks like (pseudocode):</p> <pre><code>Search the installations collection; If installation.ID equals server.InstallationID { Add to dependent installations collection; } Repeat until the whole collection is searched; for (i = 0; i &lt; dependentInstallations.length; i++) { DeleteInstallation(dependentInstallations[i]); } </code></pre> <p>DeleteInstallations is a simple function using $.postJSON function.</p> <p>The problem is the .then function executes immediately after the first JSON response.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload