Languages

Menu
Sites
Language
navigator.onLine return false even though connected to network

I am creating web application for gear s2 watch with anjularJS. My code is as follows:

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    setTimeout(function(){ 
        if (!navigator.onLine) {
            alert("Error");
        }
        else
        {
            $http.get("customers.php").then(function(response) {
                alert("Success");
            });
        }
     }, 5000);
});
</script>

This code will call customers.php every 5 seconds and that works fine when I conneced to my paired phone and display Success message. As soon as I disconnected from phone it will display Error message that is also fine because it is not connected to network, But when app is in running state and watch is again connected to phone then also it is showing Error message.

Am I need to wake-up the network someway if yes let me know how?

Please help me.

Thanks..

Edited by: Sandip Patil on 06 Sep, 2016

Responses

2 Replies
Iqbal Hossain

Hi, 

This might help you to solve your problem. This is may be purely javascript related problem. 

http://stackoverflow.com/questions/13076383/once-and-for-all-what-does-navigator-online-do

 

Also you can check Navigator OnLine property in W3School

http://www.w3schools.com/jsref/prop_nav_online.asp

 

-Thanks

Sandip Patil

Thanks..