Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot get json results from twitter using PhoneGap and jQuery
    primarykey
    data
    text
    <p>I'm trying to get the last 50 tweets using a certain hash tag, on a mobile device using PhoneGap (0.9.6) and jQuery (1.6.1). Here's my code:</p> <pre><code>function getTweets(hash, numOfResults) { var uri = "http://search.twitter.com/search.json?q=" + escape(hash) + "&amp;callback=?&amp;rpp=" + numOfResults; console.log("uri: " + uri); $.getJSON(uri, function(data) { var items = []; if(data.results.length &gt; 0) { console.log("got " + data.results.length + " results"); $.each(data.results, function(key, val) { var item = "&lt;li&gt;"; item += "&lt;img width='48px' height='48px' src='" + val.profile_image_url + "' /&gt;"; item += "&lt;div class='tweet'&gt;&lt;span class='author'&gt;" + val.from_user + "&lt;/span&gt;"; item += "&lt;span class='tweettext'&gt;" + val.text + "&lt;/span&gt;"; item += "&lt;/div&gt;"; item += "&lt;/li&gt;"; items.push(item); }); } else { console.log("no results found for " + hash); items.push("&lt;li&gt;No Tweets about " + hash + " yet&lt;/li&gt;"); } $("#tweetresults").html($('&lt;ul /&gt;', {html: items.join('')})); }); } </code></pre> <p>This code works great in a browser, and for a while worked in the iPhone simulator. Now it's not working on either the iPhone or Android simulator. I do not see any of the console logs and it still works in a browser.</p> <p>What am I doing wrong? If it's not possible to call <code>getJson()</code> on a mobile device using PhoneGap, what is my alternative (hopefully without resorting to native code - that would beat the purpose).</p> <p>Bonus: how can I debug this on a mobile simulator? In a browser I use the dev tools or Firebug, but in the simulators, as mentioned, I don't even get the log messages.</p> <p>As always, thanks for your time,</p> <p>Guy</p> <p><strong>Update:</strong><br> As @Greg intuited, the function wasn't called at all. Here's what I found and how I bypassed it:<br> I have this <code>&lt;a&gt;</code> element in the HTML <code>&lt;a href="#" id="getTweets"&gt;Get tweets&lt;/a&gt;</code><br> Then I have this code in the <code>$(document).ready()</code> function: </p> <pre><code>$("#getTweets").click(function() { var hash = "#bla"; getTweets(hash, 50); }); </code></pre> <p>That didn't call the function. But once I changed the code to:</p> <pre><code>function gt() { var hash = "#bla"; getTweets(hash, 50); } </code></pre> <p>and my HTML to:</p> <pre><code>&lt;a href="javascript:gt()" id="getTweets"&gt;Get Tweets&lt;/a&gt; </code></pre> <p>it now works and calls Twitter as intended. I have no idea what's screwed up with that particular click() binding, but I ran into similar issues with PhoneGap before. Any ideas are appreciated.</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.
 

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