网络活动不会发生

时间:2014-07-23 09:07:16

标签: javascript android jquery networking cordova

大家好,我的网络插件存在很大问题。我在登录页面上有这个代码。如果我运行带有wifi的应用程序OFF事件DISCONNECTED是火,但如果我将其设置为ON(打开的应用程序),在线事件不会触发! :(我正在使用最后一个cordova,networkinfo 2.10和jquery 2.11

var stateConnection=true;

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    document.addEventListener("offline", onOffline, false);
    document.addEventListener("online", onOnline, false);
    document.addEventListener("backbutton", onBackKeyDown, false);
}


function onBackKeyDown(e) {
    // Handle the back button
    e.preventDefault();
}
function onOffline() {
    stateConnection=false;
    console.log("DISCONNECTED");
}
function onOnline() {
    // Handle the online event
    stateConnection=true;
    console.log("CONNECTED");
}


//fine MAIN


//controllo di connessione


function checkConnection() {
    return stateConnection;
}

更新

我看到一件事......我有一个3页系统(索引,登录,有效).html 在索引我加载帐户,如果我无法重定向登录(如果我可以重定向到有效页面)。我看看我是否插入了一个带有“index.html”名称的测试页面,我为get事件连接添加了一个简单的代码我得到了它但是如果我运行index.html并且它重定向到login.html最后一个只有一次事件.....

另一个更新

我尝试删除文件阅读和重定向之前..然后工作!所以问题是文件读取的OLD代码!!我说OLD是因为我已经将FILE插件更新为1.2.0 ......这是我的旧代码:你能检查我吗?

            function getFileData(filename){
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){


                    var entry = fileSystem.root;
                    entry.getFile("bs_ne/"+filename, null, function(fileEntry){
                        fileEntry.file(function(file){
                            var reader = new FileReader();
                            // console.log("Leggo i dati salvati...");
                            reader.onloadend = function(evt) {

                                if(evt.target.result =="")
                                    $(location).attr('href',"login.html");
                                else{

                                    var arr = $.parseJSON(evt.target.result);
                                    // console.log("I dati che ho letto sono: "+arr[0]+", "+arr[1]);
                                    // console.log("Provo ad effettuare la login silezioso");
                                    sessionStorage['emailuser']=arr[0];
                                    sessionStorage['passsession']=arr[1];
                                    gotohome(arr[0],arr[1]);
                                }
                            };
                            reader.readAsText(file);
                        }, errorFile);
                    }, errorFile);
                }, errorFile);
            }

这是我用来写文件的代码:

function writeFileData(username,password){
   // console.log("STO ENTRANDO");
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){

    console.log("FILE SYSTEM OK");

    var entry = fileSystem.root;


    entry.getDirectory("bs_ne", {create:true, exclusive:true}, function(direct){

        console.log("CARTELLA OK OK");

        direct.getFile("data.dat", {create:true}, function(fileEntry){
            console.log("FILE OK");
            fileEntry.createWriter(function(writer){
                var arr= new Array(); 
                arr[0]=username;
                arr[1]=password;
                var aux = JSON.stringify(arr);


                writer.onwritestart = function(){
                    console.log("Inizio a scrivere");
                };

                writer.onerror = function(){
                    alert("ERRORE");
                };
                writer.onwriteend = function(evt) {


                    var url = "homepage.html";
                    window.location=url;
                };

                writer.write(aux);

            }, errorFile);
        }, errorFile);

    }, function(error){

        console.log("ERRORE CARTELLA :"+error.code);
        if(error.code==12){
            entry.getFile("bs_ne/data.dat", {create:true}, function(fileEntry){
                console.log("FILE OK");
                fileEntry.createWriter(function(writer){
                    var arr= new Array(); 
                    arr[0]=username;
                    arr[1]=password;
                    var aux = JSON.stringify(arr);


                    writer.onwritestart = function(){
                        console.log("Inizio a scrivere");
                    };

                    writer.onerror = function(){
                        alert("ERRORE");
                    };
                    writer.onwriteend = function(evt) {


                        var url = "homepage.html";
                        window.location=url;
                    };

                    writer.write(aux);

                }, errorFile);
            }, errorFile);
        }
        else{
            loginReturn();
        }

    }); 
}, errorFile);
}

重要更新

我已经安装了旧的FILE PLUGIN(1.1.0)并且所有工作都很精细!所以问题出在我的代码(顶部^)或1.2.0文件插件中?

0 个答案:

没有答案