B
B
BarneyGumble2021-02-18 17:58:58
AJAX
BarneyGumble, 2021-02-18 17:58:58

How to translate ajax request after 30 seconds from success to error?

I have a list of urls that differ from each other only by a number, like this:

"http://site1.ru", "http://site2.ru", "http://site3.ru"


I need to sequentially access each address via ajax and in case of success from the first request, launch the next ajax request to the next url address. I do it recursively like this (the example is just conditional):

myajax();

function myajax(counter = 1) {
    $.ajax({
        type: 'GET',
        url: 'http://site'+counter+'.ru',
        success: function(response){
            myajax(counter++);
        }
    });
}


The problem is that requests to certain addresses hang, and after 30 seconds of waiting and not receiving a response from such a request, I need to exit this recursion on error. How to do it with little blood?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2021-02-18
@BarneyGumble

Read the docs
https://api.jquery.com/jquery.ajax/
The timeout parameter is described there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question