1
我想檢查我的mysql數據庫,如果用戶正確輸入用戶名和密碼,然後進入home.html,我有一些JavaScript代碼,檢測用戶何時單擊登錄按鈕,但我不明白如何檢查數據庫與JavaScript,我知道如何在PHP中,但我不明白如何從JavaScript調用PHP或直接在JS代碼,這是一些代碼:使用javascript檢查MySql中的用戶驗證
在HTML表單:
<div id="password">
<div class="input username"><input type="text" placeholder="User name" /></div>
<div class="input password"><input type="password" placeholder="Password" /></div>
<button>Log in</button>
<a href="#" class="back">Back</a>
</div>
</div>
然後在我的Login.js文件我有這樣的:
function forgot() {
//Se ho scritto la password allora fai l'animazione wobble, altrimenti vai in home.html
if($("#password .input.password input").attr("value")!='') {
$.notification(
{
title: "Wrong password",
content: "Just leave the password field empty to log in.",
icon: "!"
}
);
$("#password").removeClass().addClass("animated wobble").delay(1000).queue(function(){
$(this).removeClass();
$(this).clearQueue();
});
$("#password .input.password input").attr("value", "").focus();
} else {
document.location.href = "home.html";
}
}
現在的登錄我只檢測,如果該字段是空的,但我想檢測mysql數據庫如何檢查它?因爲我想如果用戶輸入錯誤的用戶名和密碼跨越$通知警報,任何人都可以幫助我?
使用Ajax。如果您使用jQuery,則使用Google jQuery ajax()函數。 – bogatyrjov
感謝提示,我必須把jQuery?在.js文件中? – Piero
要麼將其放入.js文件中,並使用
您不能直接從客戶端JS通信到服務器端數據庫。
要發出HTTP請求(到服務器端程序),請使用the XMLHttpRequest object。
來源
2012-10-17 09:36:59 Quentin
我會建議使用JQuery的ajax()函數在幾年內沒有手動觸及XMLHttpRequest對象 –
我必須在JavaScript中添加jQuery? – Piero
來源
2012-10-17 12:41:07
如果您使用存儲過程,您可以在sql server端執行驗證部分
來源
2013-02-09 01:15:03 user2056241