Requesting something via ajax - how to stop other requests until this one is done
<p>I have a php script that outputs json data. For the purposes of testing, i've put sleep(2) at the start.</p>

<p>I have a html page that requests that data when you click a button, and does <code>$('.dataarea').append(data.html)</code></p>

<p>(php script returns a json encoded array. data.html has the html that i want to put at the end of <code>&lt;div class="dataarea"&gt;...HERE&lt;/div&gt;</code>.</p>

<p>The trouble is, if i click the button too fast (ie. more than once within two seconds (due to the sleep(2) in the php script)), it requests the php file again.</p>

<p>how can i make it only do one request at a time?</p>

<p>i've tried this (edited down to show the important parts):</p>

<pre><code>amibusy=false;

$('#next').click('get_next');

function get_next() {

    if (amibusy) {
    alert('requesting already');

}
else {

    amibusy=true;
    // do the request, then do the append()
    amibusy=false;

}


}
</code></pre>

<p>but this doesn't seem to work. i've even tried replacing the amibusy=true|false, with set_busy(), and set_not_busy(). (and made a function am_i_busy() { return amibusy; })</p>

<p>but none of this seems to work. what am i missing?</p>
