Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>get_each_total(function () { alert("success")}); </code></pre> <p>here you have the <code>function (){ alert ....</code> that returns a function object</p> <pre><code> get_each_total(alert("success")); </code></pre> <p>here <code>alert("success")</code> is an object of whatever type <code>alert()</code> returns and it is not a function.</p> <p><strong>Edit:-</strong> in respone to the comment i'm going to further clarify.</p> <p>when the browser sees</p> <pre><code>do_something(is_it_complete(arg1, arg2)); </code></pre> <p>it goes throught the following steps:</p> <ol> <li>Get the function <code>is_it_complete</code> and call it arguments <code>arg1</code> and <code>arg2</code>.</li> <li>get the function <code>do_something</code> and call it with the result of the above as an argument.</li> </ol> <p>When the browser sees:</p> <pre><code>do_something(function () { is_it_complete(arg1, arg2) }); </code></pre> <p>it does:</p> <ol> <li>Create a function object that calls <code>is_it_complete(arg1, arg2)</code></li> <li>Get the function <code>do_something</code> and call it with the above object as an argument.</li> </ol> <p><strong>Edit 3:-</strong> Ok so in the first one it called the alert before running your code so it appeared to work.</p> <p>you have:</p> <pre><code>get_each_total = function(callback) { // ... *snip* return requests.push($.getJSON(url, function(data) {})); return $.when.apply($, requests).then(function() { // ... *snip* }); }; </code></pre> <p>the second return is never reached.</p> <p><strong>Edit:-</strong> thought i would put a few tips after reading the code:</p> <pre><code>var requests; requests = []; </code></pre> <p>is redundant change that style to </p> <pre><code>var requests = []; var url = " ...."; </code></pre> <p>When you do not pass any arguments to a callback do no wrap it. </p> <pre><code>.then(function(){ callback();}) </code></pre> <p>it is the same as:</p> <pre><code>.then(callback); </code></pre> <p>and as mentioned in the comments your url</p> <pre><code>url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js?callback=?&amp;apikey=38A260E9D12A4908B1AF9184B691131&amp;q=justin+bieber&amp;window=d"; </code></pre> <p>Should be</p> <pre><code>url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js?callback=somevalue&amp;apikey=38A260E9D12A4908B1AF9184B691131&amp;q=justin+bieber&amp;window=d"; </code></pre> <p>or even:</p> <pre><code>url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js" $.getJSON(url, { "callback": "somevalue", "apikey": "38A260E9D12A4908B1AF9184B691131", "q": "justin bieber", "window": "d" }, function(data){ alert("Got: " + data);}); </code></pre>
    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.
    2. 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