功能實現(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)); } } }); }); });
標(biāo)簽:荊州 佛山 辛集 紅河 咸寧 商洛 揭陽 股票
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《AJAX驗證數(shù)據(jù)庫內(nèi)容并將值顯示在頁面》,本文關(guān)鍵詞 AJAX,驗證,數(shù)據(jù)庫,內(nèi)容,并將,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。