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
이벤트를 배치 할 것
안녕 도슨. 귀하의 의견을 보내 주셔서 감사합니다. 개체 함수 창에 메서드가 openDatabase가 없다는 것을보고 있습니다 ... – Arockia
이'db = Window.openDatabase','Window'는'window' 여야합니다 (모두 소문자) –
고맙습니다 Dawson. 창을 창으로 변경하여 작동했습니다. 고마워요 ... – Arockia