简体   繁体   中英

Uncaught ReferenceError in Cordova Connection

The error above happens when I try to use Cordova's checkConnection function:

cordova.js:29 Uncaught ReferenceError : require is not defined

What am I doing wrong?

function checkConnection()
{
    var networkState = navigator.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.CELL]     = "Cell generic connection";
    states[Connection.NONE]     = "No network connection";
    alert("Connection type: " + states[networkState]);
}

通过更改the config.xmltargetminimum-sdkthe config.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM