Data available only after alert
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5316697/jquery-return-data-after-ajax-call-success">jQuery: Return data after ajax call success</a>  </p>
</blockquote>



<p>I wrote a script which adds a new div container to the said with the a select field inside. The data for the select field is loaded with an ajax request before. But for some reason the  fields are only visible when I output something with alert().</p>

<pre><code>var o = '';
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: webroot + 'items',
                success: function(data) {
                    $.each(data, function(index, value) {
                        o += '&lt;option value="' + index + '"&gt;' + value + '&lt;/option&gt;';
                    });
                }
            });
            var l = parseInt($('.items .item').length);
            var h = '&lt;div class="item"&gt;&lt;span class="bold"&gt;Item ' + (l + 1) + '&lt;/span&gt;&lt;select id="ItemName" name="data[Item][name]"&gt;' + o + '&lt;/select&gt;&lt;/div&gt;';
</code></pre>

<p>I have actually no idea how to solve this problem. Can you help me?</p>
