AJAX驗(yàn)證數(shù)據(jù)庫內(nèi)容并將值顯示在頁面
更新時(shí)間:2014年08月24日 14:45:32 投稿:whsnow
光標(biāo)離開文本框,在本頁面的相應(yīng)地方獲取數(shù)據(jù)庫中改值所對(duì)應(yīng)的其他數(shù)據(jù),相應(yīng)的實(shí)現(xiàn)代碼如下,感興趣的朋友可以看看
功能實(shí)現(xiàn):
在jsp頁面中填寫文本框內(nèi)容,光標(biāo)離開文本框,在本頁面的相應(yīng)地方獲取數(shù)據(jù)庫中改值所對(duì)應(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動(dòng)態(tài)加載數(shù)據(jù)庫示例
- jquery+ajax+C#實(shí)現(xiàn)無刷新操作數(shù)據(jù)庫數(shù)據(jù)的簡(jiǎn)單實(shí)例
- ajax讀取數(shù)據(jù)庫內(nèi)容實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)下拉選擇菜單示例
- ajax對(duì)注冊(cè)名進(jìn)行驗(yàn)證檢測(cè)是否存在于數(shù)據(jù)庫中
- ajax異步刷新實(shí)現(xiàn)更新數(shù)據(jù)庫
- AJAX 自學(xué)練習(xí) 無刷新提交并修改數(shù)據(jù)庫數(shù)據(jù)并顯示
- 通過數(shù)據(jù)庫和ajax方法寫出地圖的實(shí)例代碼
相關(guān)文章
ajax請(qǐng)求成功后新開窗口window.open()被攔截解決方法
ajax 異步請(qǐng)求成功后需要新開窗口打開 url,使用的是 window.open() 方法,但是很可惜被瀏覽器給攔截了,怎么解決這個(gè)問題呢2014-09-09Jquery基于Ajax方法自定義無刷新提交表單Form實(shí)例
這篇文章主要介紹了Jquery基于Ajax方法自定義無刷新提交表單Form的方法,結(jié)合實(shí)例詳細(xì)分析了Ajax無刷新提交表單的完整實(shí)現(xiàn)過程,并總結(jié)了使用中的注意事項(xiàng),具有很好的借鑒價(jià)值,需要的朋友可以參考下2014-11-11Ajax技術(shù)(WEB無刷新提交數(shù)據(jù))-
Ajax技術(shù)(WEB無刷新提交數(shù)據(jù))-...2006-07-07