Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:00:08+00:00 2026-06-18T06:00:08+00:00

I am trying to load a data feed when my phonegap app loads. It

  • 0

I am trying to load a data feed when my phonegap app loads. It works fine, except that when I don’t have a data connection, I want the system to sense this and then give a nice message like, “Sorry you don’t have a data connection.”. Once the page is all loaded I can click a button and run a function that tells me my connection state. However, it simply won’t run this code automatically when the page loads, and I can’t figure out why. I have the same problem when I test this on iOS or Android. I’ve stripped out only the basics, so hopefully someone can’t discover the problem.

<html>
<head>
    <link rel="stylesheet" type="text/css" href="css/main.css" />   
    <script type="text/javascript" charset="utf-8" src="js/jquery-1.7.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/main.js"></script>
    <script src="js/jquery.jsonp-2.1.4.min.js"></script>    
<script>
function checkConnection() {
    var networkState = navigator.network.connection.type;
    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.NONE]     = 'No network connection';
    alert('Connection type: ' + states[networkState]);
    if(states[networkState] == 'No network connection') { show_no_connection(); }
}

$(document).ready(function(){
    checkConnection();
});

function show_no_connection() {
        $('#status').html('You Have No Data Connection!');  
}   


</script>       

</head>
<body>

 <div id="status">SO FAR, YOU HAVE A CONNECTION.</div>
     <a href='javascript:void(0);' onclick='checkConnection();'>Check your connection</a><br/><br/> 
    <script type="text/javascript" src="cordova-2.2.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>       
</body>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:00:09+00:00Added an answer on June 18, 2026 at 6:00 am

    Classic jQuery syntax $(document).ready(function(){ should not be used with jQuery Mobile, it will not work correctly not to mention it can’t be used to initialize Phonegap code. More about this topic can be found in this ARTICLE. Or find it HERE.

    This should be used to solve this problem:

    document.addEventListener("deviceready", onDeviceReady, false);
    
    // PhoneGap is loaded and it is now safe to make calls PhoneGap methods
    function onDeviceReady() {
        checkConnection();
    }
    
    function checkConnection() {
        var networkState = navigator.network.connection.type;
        var states = {};
        states[Connection.UNKNOWN]  = 'Unknown connection';
        states[Connection.ETHERNET] = 'Ethernet connection';
        states[Connection.WIFI]     = 'WiFi connection';
        states[Connection.CELL_2G]  = 'Cell 2G connection';
        states[Connection.CELL_3G]  = 'Cell 3G connection';
        states[Connection.CELL_4G]  = 'Cell 4G connection';
        states[Connection.NONE]     = 'No network connection';
        alert('Connection type: ' + states[networkState]);
        if(states[networkState] == 'No network connection') { show_no_connection();
    }
    
    function show_no_connection() {
        $('#status').html('You Have No Data Connection!');  
    }   
    

    Code needs to wait for Phonegap framework initialization and it is done like this:

    document.addEventListener("deviceready", onDeviceReady, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TableView that I am trying to load data into. From the
I have a table with composite primary key. I am trying to load data
I'm trying to load the parsed html data from an rss feed using a
I am trying to feed in some JSON data to my iPhone app, the
I'm trying to load XML data via the jQuery get method. The XML feed
I have an XML feed (which I don't control) and I am trying to
I have an Objective C application that reads data from an RSS feed using
I am trying to load data asyncronously but on the first time, no progressbar
I was trying to load a data file into mysql table using LOAD DATA
I'm facing a rather strange Issue when trying to load data from an XML-Webservice.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.