Call Function Upon Document Ready
<p>I need to start polling a URL upon the page loading, to get a JMS response from a credit card server.  I put the following together.</p>

<p>It works, but only if I hit the Refresh button on the browser.  I want the data from the URL to load  automatically when the page is first displayed, without requiring the user to Refresh.</p>

<p>I am missing a fundamental concept here, and would appreciate any advice on how to make it work. I have about 2 days of JavaScript experience so far.</p>

<pre><code>&lt;html&gt;
    &lt;body&gt;

        &lt;div id="p_results"&gt;&lt;/div&gt;

        &lt;script type="text/javascript"&gt;
            $(document).ready(function() {
                function doJMSPolling() {
                    $.ajax({
                        url: "./poll",
                        type: "GET",
                        dataType: "text",
                        success: function(json) {

                            var json = $.parseJSON(json);

                            if (json.status === 'continue-polling' &amp;&amp; json.msg === 'ok') {
                                setTimeout(function() {
                                    doPolling();
                                }, 2000);
                            }
                            else if (json.status === 'stop-polling' &amp;&amp; json.msg === 'success') {
                                for (key in json) {
                                    if (key === "providerResponse") {
                                        res = json[key];
                                        for (reskey in res) {
                                            $("#p_results").append(reskey + ":" + res[reskey] + "&lt;br&gt;"); 
                                        }
                                    }
                                }
                            } else if (json.status === 'stop-polling') {
                                $("#p_results").text(json.status);
                            }
                        }
                    });
                }
            });
        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
