我有一個腳本,我需要檢查用戶名和密碼,並顯示使用sqlite事務msg。狀態信息會在正確的條目中顯示適當的信息,但錯誤信息的警報信息不會顯示。可這個問題被固定.The腳本如下:提前其他條件與腳本與sqlite
var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS Contact1(id unique, username TEXT NOT NULL, pass TEXT NOT NULL)");
tx.executeSql("INSERT INTO Contact1(id, username, pass) VALUES (1, 'pp1', '321')");
// tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "logmsg")');
});
$(document).ready(function() // Call function when page is ready for load..
{
db.transaction(function (tx) {
tx.executeSql("INSERT INTO Contact1(id, username, pass) VALUES (3, 'pp1', '321')");
});
$("#sub").click(function(){
var uname = $("#username").val();
var password = $("#password").val();
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM Contact1 WHERE username=?', [uname], function (tx, results) {
var len = results.rows.length, i;
// msg = "<p>Found rows: " + len + "</p>";
//document.querySelector('#status').innerHTML += msg;
for (i = 0; i < len; i++){
// msg = "<p><b>" + results.rows.item(i).pass + "</b></p>";
//document.querySelector('#status').innerHTML += msg;
if(results.rows.item(i).username == uname){
// alert("hello");
tx.executeSql('SELECT * FROM Contact1 WHERE pass=?', [password], function (tx, results) {
var len = results.rows.length, i;
msg = "<p>Found rows: " + len + "</p>";
document.querySelector('#status').innerHTML += msg;
for (i = 0; i < len; i++){
msg = "<p><b>" + results.rows.item(i).username + "</b>==><b>" + results.rows.item(i).pass + "</b></p>";
document.querySelector('#status').innerHTML += msg;
}
}, null);
}
else
{//wrong username/password case
msg="<p><b>Please enter the right Username and password"+"</b></p>";
document.querySelector('#status').innerHTML += msg;
}
}
}, null);
});});});
感謝:d
非常感謝,這工作,我只是不得不刪除成功味精,並在那裏放置'導航URL'!乾杯 – rawatdeepesh