Answer the question
In order to leave comments, you need to log in
How to get Ajax status into a variable?
I have a code that iterates over the API, and I wanted to make it stop when there was an empty request in the chicle.
Here is the code
for (let i = 0; i < 250; i++) {
$.ajax({
url: "api/page="+i,
type: 'GET',
dataType: 'json',
async: false,
success: function(res) {
for (let i = 0; i < 250; i++) {
var id = res['_embedded']['tasks'][i]['id'];
if(id_task =="undefined" || id_task == null || id_task == ''){
break;
}
Answer the question
In order to leave comments, you need to log in
for (var i = 0; i < 250; i++) {
var response = await $.ajax('api/page=' + i);
console.log('Получены данные:');
console.dir(response);
// Здесь впиши условие остановки:
if (условие) {
i = 250; // Увеличиваем счетчик до 250, это приведет к остановке цикла
}
}
// Здесь пиши дальше свой код
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question