petko_stankoski
petko_stankoski

Reputation: 10713

Ajax sync or async

I have two ajax calls. Both are sync. Both call methods from one controller. But the second method gets hit first. Why is this and how to change it?

Upvotes: 0

Views: 462

Answers (1)

Umesh Aawte
Umesh Aawte

Reputation: 4690

As name said Ajax - Asynchronous JavaScript

Ajax is async


Edit

For you question you can do like calling second URL on response of first one, A simple jQuery example is,

/*First request*/
$.post("{SOME_URL}", { PARAMS },
    function(data) {
        /*Do anything with data*/
        /*Your second request*/
        $.post("{SOME_URL}", { PARAMS },
            function(data) {
                /*Do anything with data*/
            }
        );
    }
);

Moreover jQuery supports async flag that can be set to false to activate Asynchronous nature of the query. But this will block all other request from same page.

Please read more on this here

Upvotes: 1

Related Questions