I have 3 $.ajax requests in a page that gets JSON content from the server and fills up three separate divs. The content in these three divs is pretty large so it takes a while to load all the content. Also these ajax calls are called on page load, so something like:
$(document).ready(function () {
$.ajax({
type: 'POST',
url: "/controller/action",
dataType: 'json',
traditional: true,
async: false,
success: function (data) {
//fill content in div 1
}
});
$.ajax({
type: 'POST',
url: "/controller/action2",
dataType: 'json',
traditional: true,
async: false,
success: function (data) {
//fill content in div 2
}
});
$.ajax({
type: 'POST',
url: "/controller/action3",
dataType: 'json',
traditional: true,
async: false,
success: function (data) {
//fill content in div 3
}
});
});
My big questions are:
Thanks a lot! Clockwork
The page will load first, your function will be executed once it's ready.
To make the GUI responding and to do the ajax requests simultaneously, remove the async:false
option.
You can move this code to $(document).load( .... ).
And the 3 calls will started at the same time. Their finish time is not guaranteed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.