Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Neither example works. (Hint to reviewers: it is the last two lines of which he speaks.)</p> <p>In your first example, you call <code>alert()</code>, which raises the alert dialog, <em>even before the <code>get_each_total()</code> function is called.</em> Javascript invokes it, showing the alert (and giving the illusion than something happened), and passes the result of the <code>alert()</code> call to <code>get_each_total()</code> (and does the same with the alert in the following function, too). The result is null. If the callback were ever called, this would raise an error.</p> <p>In the second example, you're declaring a function and passing a reference to it to <code>get_each_total()</code>, which can then be called via your <code>callback()</code> expression. A function is something that responds to the <code>()</code> operator, meaning "do this." It would actually do something (show the alert) if your code succeeded.</p> <p>But your code does not. Going to the fiddle, and looking at the console, I see this message: "Failed to load resource: the server responded with a status of 500 (Internal Server Error)." <code>getJSON()</code> never triggers the callback because <em>it never succeeds</em>.</p> <p>[EDIT] @austinbv pointed out to me that I'd missed something. The 500 code is a deliberate test on his part. But his code is still broken in <code>get_each_total_broken()</code>; there is a misplaced <code>return</code> in the line</p> <pre><code>return requests.push($.getJSON(url, function(data) { })); </code></pre> <p>This returns immediately from <code>get_each_total_broken</code>. The <code>when().then()</code> clause is never invoked, so he never sees the error handling. The immediacy of the alerts in the first example continues to give the illusion that something happened.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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