I am completely new to Phonegap and Javascript. I am trying to save the username value and password value from the login form to sqlite database.
This is my login.html file:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Login</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="js/iscroll.js"></script>
<script type="text/javascript" src="js/login.js"></script>
</head>
<body>
<div class="wrapper">
<form action="submit" id="login" name="login_form">
<input type="text" id="uName" name = "UserName" placeholder="Username" value="Admin"/>
<br/>
<input type="password" id="password" name = "Password" placeholder="Password" value="super@1234"/>
<br/>
<button type="submit" id="submit" value="Submit">Login</button>
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#submit").click(function() {
if($("#uName").val()==""){
alert("Please fill username field.");
//$("#uName").focus();
}
else if($("#password").val()==""){
alert("Please fill password field.");
//$("#password").focus();
}
else {
onDeviceReady();
}
});
});
</script>
</div>
</body>
</html>
and this is my login.js file:-
var db;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
db = window.openDatabase("UserDB", "1.0", "Login", 10000);
db.transaction(populateDB, transaction_err, populateDB_success);
}
function populateDB(tx) {
var userName = document.getElementById("uName").value;
var password = document.getElementById("password").value;
tx.executeSql('CREATE TABLE IF NOT EXISTS users (ID INT, USERNAME VARCHAR UNIQUE, PASSWORD VARCHAR)');
tx.executeSql('INSERT INTO users (ID,USERNAME,PASSWORD) VALUES ("'+1+'","'+userName+'","'+password+'")');
alert("" + userName + " " + password);
}
function transaction_err(tx, error) {
alert("Database Error: " + error);
}
function populateDB_success(tx) {
alert("Data successfully entered.");
window.open("file:///assets/www/view_login.html");
}
My problem is when I am running this code in my android device it gives me application error : There is a network error and error log is:-
04-30 10:16:35.080 31868-31868/com.itpp.trt D/CordovaWebViewImpl onPageDidNavigate(file:///android_asset/www/submit?UserName=Admin&Password=super%401234)
04-30 10:16:35.080 31868-31934/com.itpp.trt E/AndroidProtocolHandler﹕ Unable to open asset URL: file:///android_asset/www/submit?UserName=Admin&Password=super%401234
04-30 10:16:35.090 31868-31868/com.itpp.trt D/SystemWebViewClient﹕ CordovaWebViewClient.onReceivedError: Error code=-1 Description=There was a network error. URL=file:///android_asset/www/submit?UserName=Admin&Password=super%401234
I cant find where is the problem please help me. Thanks and sorry for the long question. :)
Aucun commentaire:
Enregistrer un commentaire