How can I refresh the page through jQuery and make sure there is a connection?

I played with .load () and .ajax (), but I did not get to the end. Here's what I need: Everey, the function should check if it can load a specific page. if the connection succeeds, I want to refresh the page; if not, nothing will happen, the script will try again later.

I am using jQueryTimers plugin. this is my code:

//reload trigger
$(document).everyTime('60s', 'pagerefresh', reloadPage, 0, true);

//refresh function
function reloadPage() {
    $.ajax({
        url:'index-1.php',
        type:'HEAD',
        success: location.reload(true)
        })
}

I do not know how to tell jQ what I want. Any hint was appreciated.

+3
source share
2 answers

By writing success: location.reload(), you call reloadimmediately and set the parameter successfor the return value reload(which undefined)

, reload success, :

    success: function() { location.reload(true); }
+9

SLaks, jQuery .

, - , . :

$.ajax({
        url:'index.php',
        type:'HEAD',
        success: function() { location.reload(true); },
        error: function() {$('DIV').append('<p>ERROR</p>');}
        })
0

Source: https://habr.com/ru/post/1744415/


All Articles