Answer the question
In order to leave comments, you need to log in
How to cram an array of requests into $.when?
Good afternoon. I make requests to the page, add to the array. It is necessary that the when function work with an array, or something similar. I wrote a similar code in Greasemonkey (I gave the toaster as an example):
this.$ = this.jQuery = jQuery.noConflict(true);
$(function () {
$(document).ready(function()
{
console.log('start');
var link1 = "https://toster.ru/";
var link2 = "https://toster.ru/questions";
var queryArray = [];
var query1 = $.get(link1).done(function($page){console.log("page1 loaded");});
var query2 = $.get(link2).done(function($page){console.log("page2 loaded");});
queryArray.push(query1);
queryArray.push(query2);
$.when(queryArray).done(function(){console.log("all pages loaded");});
console.log('end');
});
});
start
all pages loaded
end
page1 loaded
page2 loaded
$.when(query1, query2).done(function(){console.log("all pages loaded");});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question