K
K
KasperOffskyy2015-11-08 11:24:10
PHP
KasperOffskyy, 2015-11-08 11:24:10

How to make $.ajax requests work after internet connection is restored?

Hello.
There is this script:

function preload(){
$.ajax({
type: "GET",
url: "/script.php",
cache: false,
success: function(q){  
//действия с ответом
alert(q);
}});
};


preload() sends a request to script.php via a timer and gets a response every 5 seconds.

But if you break the connection to the Internet, and then restore it again, the script "stops" and does not load anything else, although the connection has long been restored ...

What can you think of in this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KasperOffskyy, 2015-11-08
@KasperOFFsky

The solution turned out to be this:
after
success: function(q){
//actions with the response
alert(q);
}
add
,error : function (xhr, ajaxOptions, thrownError){ setTimeout(200,preload()) }
And everything works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question