Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery - ensure code block executes after AJAX calls complete?
    primarykey
    data
    text
    <p>I currently have some JQuery code, where I am trying to ensure one block of code is executed only after the AJAX calls in the first block have been completed. I'm having some problems, however - I have tried to use the JQuery Deferred method to do this (code below), but neither the first or second code blocks are running, so I assume I am on the wrong track.</p> <p>I am new to the Deferred methods, so I'm hoping someone can point me in the right direction, or point out another (perhaps better) way of doing this.</p> <pre><code>function makeChains(){ $('.chained_to_vehicle_make_selector').remoteChainedTo('.chained_parent_vehicle_make_selector', '/models.json'); $('.chained_to_vehicle_model_selector').remoteChainedTo('.chained_parent_vehicle_model_selector', '/trims.json'); $('.chained_to_vehicle_trim_selector').remoteChainedTo('.chained_parent_vehicle_trim_selector', '/model_years.json'); } var chainCall = $.Deferred(function() { makeChains(); }); chainCall.done(function() { $(".chzn-select").chosen(); $(".chained_parent_vehicle_make_selector").chosen().change( function() {$(".chained_to_vehicle_make_selector").trigger("liszt:updated"); }); $(".chained_parent_vehicle_model_selector").chosen().change( function() {$(".chained_to_vehicle_model_selector").trigger("liszt:updated"); }); $(".chained_parent_vehicle_trim_selector").chosen().change( function() {$(".chained_to_vehicle_trim_selector").trigger("liszt:updated"); }); $(".chained_child").chosen(); }); </code></pre> <p>I have also tried adding <code>chainCall.resolve();</code> to the end, but to no avail.</p> <p>Can anyone assist?</p> <p>EDIT: I've had a look at the solution here: <a href="https://stackoverflow.com/questions/6250022/waiting-for-jquery-ajax-responses?rq=1">Waiting for jQuery AJAX response(s)</a> which seems like it would work, but I think the problem might be that <code>remoteChainedTo</code> doesn't seem to have a built-in callback? Would I need to modify the code to add a callback for this to work, or will JQuery be able to help me? The remoteChainedTo plugin is using <code>getJSON</code> to pull the data from the url.</p> <p>EDIT 2: Not much love for this question - any further ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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