Is it somehow possible to load more files via AJAX?
Example
$.ajax({
url: ["test1.html", "test2.html", "test3.html"],
success: function(data1, data2, data3) {
// Do something
}
});
Because I would like to avoid callbacks…
$.ajax({
url: "test1.html",
success: function(data) {
$.ajax({
url: "test2.html",
success: function(data) {
$.ajax({
url: "test3.html",
success: function(data) {
// Do something
}
});
}
});
}
});
I prefer to write recursive functions and use a stack for something like this. This will only run
successorerroronce at the end of the processing and will fetch each url sequentially. However, fetching them sequentially may make the loading take longer because it does not allow the browser to parallelize the requests! A different variation from this just be to run all the requests parallel and just process the results sequentially.As I just typed this up, there may be some small errors, but the concept is sound. There is more that can be done such as passing values/results out, but those are left as an exercise 😉 With the same warning applying, here is a version which just processes the results sequentially — the requests may be sent in parallel:
Happy coding.