How to catch net::ERR_CONNECTION_REFUSED

前端 未结 3 1436
囚心锁ツ
囚心锁ツ 2020-12-13 12:25

Is there a way to catch failed to load resource: net::ERR_CONNECTION_REFUSED, I\'ve tried:

try {
  $.post(\'\',{},function(res) {
  }).fail(fun         


        
3条回答
  •  忘掉有多难
    2020-12-13 12:55

    You have access to online/offline in chrome.

    var _Network_state = true;
        function updateIndicator() {
            // Show a different icon based on offline/online
            if (navigator.onLine) { // true|false
                // ... do other stuff
                _Network_state = true;
            } else {
                // ... do other stuff
                _Network_state = false;
            }
            console.info(_Network_state ? 'Online' : 'Offline');
        }
        // Update the online status icon based on connectivity
        window.addEventListener('online',  updateIndicator);
        window.addEventListener('offline', updateIndicator);
        updateIndicator();
    

    Before call ajax, inspect "_Network_state"

提交回复
热议问题