But, stopping and waiting for the data will freeze the application,
and that's the whole point of asynchronous requests - to avoid
stopping the responsiveness of the application that is running.
Maybe you can shift some of the checking to the back-end, so the data
comes prepared and ready to be displayed in the browser.

If you cannot alter your app and must wait, then display some kind of
throbber and a message and use a synchronous request to the back end
(php script).
I use the following function for synchronous requests - it waits until
the PHP script finishes and then continues:

function sjaxObject(url) {
        var AJAX = null;
        if (window.XMLHttpRequest) {
                AJAX=new XMLHttpRequest();
        }
        else {
                AJAX=new ActiveXObject("Microsoft.XMLHTTP");
        }

        if (AJAX) {
                AJAX.open("POST", url, false);
                AJAX.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
                AJAX.send(null);
                return AJAX.responseText;
        }
        else {
                return false;
        }
}





On Jul 5, 2:28 pm, NicoSalto <[email protected]> wrote:
> hello,
>
> My problem is simple i think but i didnt find any solution yet.
>
> I have a javascript loop. In this one there are a JSON request which
> ask some data from a php script. My JSON request take time to come
> back (5secondes each). I would like to stop the loop and wait for the
> JSON answer before the loop continue.
> Because now when i run the script, all the JSON request start almost
> in the same time!
>
> I try with : this.stop();
> but without result...
>
> if somebody have any idea.

Reply via email to