2014-04-29 5 views
0

phonegap을 사용하여 DB 및 테이블을 만들려고했습니다. 나는 phonegap 문서를 따라 갔지만 나는 식별 할 수없는 잘못된 것을하고있다. 아무에게나 의미있는 사람은 나에게 도움이 될 것입니다. 내 코드가 여기에 있습니다.Phonegap 저장소가 작동하지 않습니다.

<!DOCTYPE html> 
<html> 
<head> 
<title>Daily Word</title> 
<link rel="stylesheet" href="../css/jquery.mobile-1.4.2.min.css"> 
<link rel="stylesheet" href="../css/style.css"> 
<script src="../js/jquery-1.9.1.js"></script> 
<script src="../js/cordova.js"></script> 
<script src="../js/jquery.mobile-1.4.2.min.js"></script> 
<script> 
    document.addEventListener("deviceready", onDeviceReady, false); 

var db; 
var user_type; 

function onDeviceReady() 
{ 
    alert("Device Ready"); 
    db = Window.openDatabase("DailyWord","1.0","DailyWord DB",2*1024*1024); 
    db.transaction(createDB,errorDB,successDB); 
    alert("DB Query fired..."); 
} 
//This will cereate the database 
function createDB(tx) 
{ 
    tx.executeSql('DROP TABLE IF EXISTS Login'); 
    tx.executeSql('CREATE TABLE IF NOT EXISTS Login (type)'); 
    tx.executeSql('CREATE TABLE IF NOT EXISTS DW_Words(id unique,status)'); 
    alert("DB Created");   
} 
//This will report the error in the db connection 
function errorDB(err) 
{ 
    alert("Error in creating DB"+err.code); 
} 
//This will report the success state of db connection 
function successDB() 
{ 
    alert("DB Created");  
} 
function insertUser(tx) 
{ 
    var sql='INSERT INTO Login(type) VALUES (?)'; 
    tx.executeSql(sql,[user_type],SuccessQueryDB,errorDB); 
} 
function SuccessQueryDB(tx) 
{ 
    alert("Query"); 
    tx.executeSql('SELECT * FROM Login',[],redirectUser,errorDB); 
} 
function redirectUser(tx,results) 
{ 
    //var rows=results.rows.length; 
    return "Success"; 
} 
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 Connection'; 
    return states[networkState]; 
} 
</script> 
</head> 
<body> 
<div data-role="page" id="LoginPage"> 
    <div data-role="header" id="header"><h4>Daily Word</h4></div> 
    <div data-role="content"> 
    <form> 
    <fieldset> 
    <input type="text" name="Username" class="Username" id="text-basic" value="arockia" onfocus="if (this.value == 'Username') this.value = '';" onblur="if (this.value == '') this.value = 'Username';"> 
    <input type="password" name="Password" class="Password" id="text-basic" value="arulbhuvi" onfocus="if (this.value == 'Password') this.value = '';" onblur="if (this.value == '') this.value = 'Password';"> 
    <input type="button" value="Login" name="btnLogin" id="btnSignIn"> 
    <input type="reset" value="Reset" name="btnClear"> 
    <a href="register.html" data-role="button" id="SignUp">Sign Up</a> 
    </fieldset> 
    </form> 
    </div> 
    <div data-role="footer" data-position="fixed" id="footer" ><h4><a href="http://eazytutor.in/Mobile/">EazyTutor</a></h4></div> 
<script> 
$("#LoginPage").on('pageinit' , function (event) { 
    $("#btnSignIn").on('click', function(){ 
     var uname=$('.Username').val(); 
     var pwd=$('.Password').val(); 
       if(checkConnection() == "No Connection") 
       { 
        alert("Please check internet connection"); 
       } 
       else 
       {  
        $.get("http://eazytutor.in/DailyWord/login.php?Username="+uname+"&Password="+pwd,function(response){ 
        if(response == "Admin") 
         { 
          user_type=response; 
          db.transaction(insertUser,errorDB); 
          window.location.href ="Admin/admin_home.html"; 
         } 
        else if(response == "User") 
         { 
          user_type=response; 
          db.transaction(insertUser,errorDB); 
          window.location.href="User/index.html"; 
         } 
        else 
         { 
          alert(response); 
         } 
        }); 
       } 
    }); 
}); 
</script> 
</div> 
</body> 
</html> 
당신은 DOM이 완전히로드 된 후 호출되는 함수에 deviceready 이벤트를 배치 할 것

답변

1

. 이 도움이 될 것입니다 : 그것은 폰갭 그들을 받아 들일 준비가되기 전에 호출되는 방법의 가능성을 줄여로

<body onload="onLoad()"> 

function onLoad() { 
    document.addEventListener("deviceready", onDeviceReady, false); 
} 

이것은 폰갭/코르도바위한 가장 좋은 방법이다. ALSO

:

이 라인 :

<script src="../js/cordova.js"></script> 

가 있어야한다 : 폰갭/코르도바 당신이 빌드 명령을 실행할 때이 파일을 추가하고 있기 때문에

<script src="cordova.js"></script> 

이것은 항상 것입니다 프로젝트 루트에 추가됩니다.

+0

안녕 도슨. 귀하의 의견을 보내 주셔서 감사합니다. 개체 함수 창에 메서드가 openDatabase가 없다는 것을보고 있습니다 ... – Arockia

+0

이'db = Window.openDatabase','Window'는'window' 여야합니다 (모두 소문자) –

+0

고맙습니다 Dawson. 창을 창으로 변경하여 작동했습니다. 고마워요 ... – Arockia

관련 문제