How to use json data that 'arrives' X seconds later?
<p>I'm filling out a list with a json. However that json (php file) gives me the result X seconds later (unknown time). </p>

<p>External file - Getting the json data:</p>

<pre><code>$(function(){
                // can't modify this file
                $.getJSON('json.php',
                    function(data) {            
                    items = [];
                    $.each(data, function(key, val) {
                            items.push('&lt;li id="' + key + '"&gt;' + val + '&lt;/li&gt;');
                    });
                });
    });
</code></pre>

<p>Inline code - Output:</p>

<pre><code>&lt;script&gt;   
 $(function(){
                $('&lt;ul/&gt;', {
                        'class': 'my-new-list',
                        html: items.join('')
                }).appendTo('#result');
        });
&lt;/script&gt;
</code></pre>

<p>Right now I see nothing in <code>#result</code> because both codes are being loaded at the same time so the output can't find the 'items'. </p>

<p>How could I modify the <strong>Inline code</strong> in order to force it to wait until the external file gives me the json data ? Maybe an observer ?</p>

<p>EDIT: It looks like I didn't explain it well enough. I'm sorry for my poor english. I'm also a Js/Jquery newbie.</p>

<p>EDIT 2: If we have no delay getting the json data everything works, however it depends on some external devices connected through serial communications and sometimes it takes 2,3 or 5 seconds to get the json.</p>
