Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call a function before $.post() callback displays alert()?
    primarykey
    data
    text
    <p>I'll note that this code is not something I built, I'm simply making some UI changes using a plugin on a system that's already in place.</p> <p>I'm building a plugin that's utilizing <a href="http://www.malsup.com/jquery/block/" rel="nofollow">blockUI</a> (yes, I need to build a plugin with a plugin) in order to display a loading icon over certain elements when an Ajax call is fired, however this one in particular calls an <code>alert()</code> if the <code>success()</code> event doesn't get the response it needs.</p> <p>The result of this is my loading icon calling <code>fadeOut()</code> <em>after</em> the <code>alert</code> fires, which is not what I want it to do.</p> <p>When I call the function I'm building, I pass in <code>$.post()</code> complete with the settings and options I need, like this:</p> <pre><code>$.fn.startLoading({ element: $("div"), ajax: $.post('some.url', { //Ajax settings... }, function (response) { //This is the success function, right? if (good) { //stuff } else alert("Bad!"); //This happens BEFORE fadeOut() } }, 'text') .error(function (msg) { alert('Worse error!'); }) }); </code></pre> <p>My plugin's function takes all of this in as one <code>options</code> parameter, like so:</p> <p><code>$.fn.startLoading = function (options) { ...</code></p> <p>I then access the <code>$.post()</code> call like this:</p> <pre><code>if (options.ajax) ajax = options.ajax; </code></pre> <p>This is where I'm stuck. I need to make sure that the <code>fadeOut()</code> happens before the <code>success</code> event is fired. How can I do this using the <code>ajax</code> variable I've created in my plugin?</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.
    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