Ben
Ben

Reputation: 62384

$http.get() not triggering new network requests when cache is false

The below code is intended to block a user from doing anything if the backend system has gone away and/or is offline. I'm having an issue where no success/error is being triggered. Also, no new network requests appear in the "Network" tab in chrome after the first request entry. I thought it might be a caching issue despite the docs saying caching is disabled by default. So I disabled the cache for this request and it still doesn't ever show any error/success in the console. However, it does show checking system status every time it runs.

    var checkSystemStatus = function () {
        var timeout = 4,
            timerMessages = {};
            timerMessages[0] = "Check system...";
            timerMessages[timeout-1] = "Checking system in [[seconds]]...";
            timerMessages[timeout] = "System is offline";

        console.log('checking system status');
        $http.get(apiUrl+'/system/isOnline', {cache: false}).
            success(function(r) {
                console.log('success');
                if (r == 'true' && NotificationService.isBlockingDialogVisible()) {
                    document.location.reload(true);
                } else if (r != 'true') {
                    NotificationService.showBlockingTimer(timerMessages, timeout);
                }
            }).
            error(function (r) {
                console.log('error');
                NotificationService.showBlockingTimer(timerMessages, timeout);
            });

        setTimeout(function () {
            checkSystemStatus();
        }, (timeout+1) * 1000);
    }
    checkSystemStatus();

Any thoughts as to why I'm not seeing any network activity or getting a success/failure trigger?

Upvotes: 0

Views: 466

Answers (2)

Ven
Ven

Reputation: 19040

Try to use $timeout instead of setTimeout, else you're gonna run out of angular's "run loop", that might be why.

Upvotes: 1

p e p
p e p

Reputation: 6674

I ran into something very similar when writing something almost identical, also an IsOnline function. I bypassed the problem by appending large random number at the end of the request URL, as a query string parameter, to avoid caching. This doesn't directly answer the question but I found it to be a suitable alternative.

Upvotes: 0

Related Questions