主頁 > 知識庫 > AJAX驗(yàn)證數(shù)據(jù)庫內(nèi)容并將值顯示在頁面

AJAX驗(yàn)證數(shù)據(jù)庫內(nèi)容并將值顯示在頁面

熱門標(biāo)簽:阿里云 Mysql連接數(shù)設(shè)置 Linux服務(wù)器 電子圍欄 服務(wù)器配置 科大訊飛語音識別系統(tǒng) 銀行業(yè)務(wù) 團(tuán)購網(wǎng)站

功能實(shí)現(xiàn):

在jsp頁面中填寫文本框內(nèi)容,光標(biāo)離開文本框,在本頁面的相應(yīng)地方獲取數(shù)據(jù)庫中改值所對應(yīng)的其他數(shù)據(jù)。

servlet:

request.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
// 調(diào)用servlet層去數(shù)據(jù)庫查找是否有相同用戶名 并返回到頁面中的其他記錄
String client_id = request.getParameter("client_id");
ClientServices clientServices = new ClientServices();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Client client = clientServices.findClientById(client_id);
if (client != null) {
out.print(URLEncoder.encode(client.getClient_name(), "utf-8"));
} else {
out.print("false");
}
out.flush();
out.close();

jquery:

$(document).ready(function() {
$("#client_id").blur(function() {
$.ajax({
type : 'POST',
url : 'servlet/validServlet?client_id=' + $(this).val(),
data : 'client_id=' + $("#client_id").val(),
success : function(msg) {
if (msg == 'false') {
alert("沒有此人");
} else {
//utf-8解碼解決中文亂碼
$("#clientInfo").html(decodeURI(msg));
$("#clientInfo").attr("value", decodeURI(msg));
}
}
});
});
});
您可能感興趣的文章:
  • Ajax動態(tài)加載數(shù)據(jù)庫示例
  • jquery+ajax+C#實(shí)現(xiàn)無刷新操作數(shù)據(jù)庫數(shù)據(jù)的簡單實(shí)例
  • ajax讀取數(shù)據(jù)庫內(nèi)容實(shí)現(xiàn)二級聯(lián)動下拉選擇菜單示例
  • ajax對注冊名進(jìn)行驗(yàn)證檢測是否存在于數(shù)據(jù)庫中
  • ajax異步刷新實(shí)現(xiàn)更新數(shù)據(jù)庫
  • AJAX 自學(xué)練習(xí) 無刷新提交并修改數(shù)據(jù)庫數(shù)據(jù)并顯示
  • 通過數(shù)據(jù)庫和ajax方法寫出地圖的實(shí)例代碼

標(biāo)簽:萍鄉(xiāng) 衡水 蚌埠 江蘇 大理 棗莊 廣元 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《AJAX驗(yàn)證數(shù)據(jù)庫內(nèi)容并將值顯示在頁面》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266