Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found 2 problems with your code:</p> <p>1) If you want to iterate 2 times, your <code>for</code> function should be like this: <code>for (var i = 0; i &lt; 2; i++)</code> </p> <p>2) You must have in consideration that the function that gets called in <code>$.getJSON</code> runs asynchronously, so when that function gets called the <code>for</code> will have already finished, therefore you can't use the <code>i</code> value with that purpose inside that function.</p> <p>So, after correcting those 2 things in your code you should be able to get what you want. Try with something like this:</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;script&gt; var lat = [41.9716, 42.0411]; var lng = [-87.7026, -87.6900]; var count = 1; $(document).ready(function () { for (var i = 0; i &lt; 2; i++) { $.getJSON('http://search.twitter.com/search.json?q=business&amp;geocode=' + lat[i] + ',' + lng[i] + ',5mi&amp;lang=en&amp;callback=?', function (data) { var data = data.results; var html = ""; for (var j = 0; j &lt; 3; j++) { html += "&lt;div style='width:600px;border:solid thin blue'&gt;&lt;img src='" + data[j].profile_image_url + "'/&gt;&lt;a href='http://twitter.com/" + data[j].from_user + "'&gt;@" + data[j].from_user + "&lt;/a&gt;: " + data[j].text + "&lt;/div&gt;"; } $('.content' + count++).html(html); }); } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="content1"&gt;&lt;/div&gt; &lt;div class="content2"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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