samedi 14 février 2015

one time login in phonegap sqlite


Dear all i have one major problem in phonegap that is i wrote code for one time login using sqlite. but the problem is with me that when on success of ajax it entered in next page like welcome.html page. but there are some ajax i written in welcome page that is not getting call. i am very upset with this problem. but when i removing this sqlite(that i used for one time) then it working fine according to my requirement.and some time one time login working in emulator




<script src="http://ift.tt/1vKc4IR 1.3.2.min.js"></script>
<script type="text/javascript" src="js/cordova.js"></script>
<link rel="stylesheet" href="http://ift.tt/1cjV4we" />

function createDB(){
db = window.openDatabase("Doc", "1.0", "DocDB", 300000); //will create database Dummy_DB or open it
db.transaction(populateDB);
}
function populateDB(tx){
tx.executeSql('CREATE TABLE IF NOT EXISTS login (username TEXT, password TEXT)');
db.transaction(loginDetails);
}
function loginDetails(tx){
tx.executeSql('select * from login',[],querySuccess);
}
function querySuccess(tx, result) {
var len = result.rows.length;
if (len > 0) {
window.location='welcome.html';
}
else{
$("#d1").show();
} }
$(document).ready(function() {
window.setTimeout(function() {
navigator.splashscreen.hide();
}, 5000);
createDB();
$("#b").click(function(){
var user_id=$('#user_id').val();
var mobile=$("#mobile").val();
$.ajax({ async:true,
type:"POST",
url:"/test.php",
data:{user_id:user_id,mobile:mobile},
success:function(response){
if(response==1){
alert("Login successful");
db.transaction(insert);
function insert(tx) {
tx.executeSql('INSERT OR IGNORE INTO login(username,password) VALUES ("'+ user_id +'","'+ mobile +'")');
$("#d1").hide();
window.location='welcome.html';
}
}
else{
alert("invalid user-name and password ");
}
},
error:function(response){
alert("error");

}
});
});
**My html code is**
<div data-role="page" id="container">
<div data-role="header">
<h1>Login page </h1>
</div>
<div data-role="content">
<form method="POST" action="" id="frm">
<div id="d1" style="margin-top:10%">
<div data-theme='c' id="d12">
<input type="text" id="user_id" name="user_id" placeholder="User ID...." />
<input type="number" id="mobile" name="mobile" placeholder="mobile.." />
</div>
<div id="s" align="center">
<a input type="button" id="b" class="button" />Login</a>
</div>
</div>
</form>
</div>
</div>

Aucun commentaire:

Enregistrer un commentaire