Note that there are some explanatory texts on larger screens.

plurals
  1. POJSon/Jquery request with a setTimeout always returns a "null" result? (for Twitter Search API)
    primarykey
    data
    text
    <p>I make a call to the twitter API. 100 posts are retreived + a properties that tells me what the next page to call is. So I wait 5 sec. and call that next page, but the JSon results in the callback function is always null the second time... I think it's probably a JQuery problem...</p> <p>Here's the code to test it if you want :</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="./jquery-1.4.2.min.js"&gt;&lt;/script&gt; &lt;script&gt; function test() { var rqUrl = "http://search.twitter.com/search.json?q=%23apple+OR+%23ipad&amp;rpp=100&amp;callback=?" callTwitterSearchApi(rqUrl); } function callTwitterSearchApi(tiwtterRequestUrl) { debug("request to twitter : " + tiwtterRequestUrl); // *** FIRST CALL WORKS GREAT... *** $.getJSON(tiwtterRequestUrl, callTwitterSearchApi_callback); } function callTwitterSearchApi_callback(jsonPostsResults) { debug("callback"); if (jsonPostsResults == null) { debug("Why is jsonPostsResults null? If I copy paste the request inside a browser, I get something =("); return; } if (jsonPostsResults.error != undefined &amp;&amp; jsonPostsResults.error != "") { debug("twitter api error"); } var posts = new Array(); $(jsonPostsResults.results).each(function() { posts.push(this); }); debug("Number of posts : " + posts.length); if (jsonPostsResults.next_page != undefined &amp;&amp; jsonPostsResults.next_page.trim() != "") { debug("calling next request in 5 sec..."); // *** WHEN COMMING BACK FROM THAT LINE, JSON RESULTS == NULL?! **** setTimeout("callTwitterSearchApi(\"http://search.twitter.com/search.json" + jsonPostsResults.next_page + "\")", 5000); } } function debug(message) { document.getElementById('debug').innerHTML = message + "\n" + document.getElementById('debug').innerHTML; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="button" onclick="test();" value="test" /&gt;&lt;br /&gt; &lt;textarea id="debug" cols="80" rows="20"&gt;&lt;/textarea&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>So, at line 20, at the second callback (back from the setTimeout), the parameter "jsonPostsResults" is always returned as null... I have no idea why. If I copy paste that 2nd request in a browser, it returns 100 results. Anybody had a problem like that with the Ajax/JQuery functions when calling it with a setTimeout?</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