Ajax validates the contents of the database and displays the values on the page _ajax related

Source: Internet
Author: User

Function implementation:

Fill in the text box content in the JSP page, the cursor leaves the text box, in the corresponding place of this page obtains the other data which the database changes the value corresponding.

Servlet:

Request.setcharacterencoding ("Utf-8");
PrintWriter out = Response.getwriter ();
Call the servlet layer to go to the database to find out if there are identical user names and return to other records on the page
String client_id = Request.getparameter ("client_id");
Clientservices clientservices = new Clientservices ();
try {
thread.sleep;
} 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 '), u RL: ' servlet/validservlet?client_id= ' + $ (this). Val (), Data: ' client_id= ' + $ ("#client_id"). Val (), Success:function (ms g) {if (msg = = ' false ') {alert ("No this Person");} else {//utf-8 decoding resolves Chinese garbled $ ("#clientInfo"). HTML (decodeURI (msg)); $ ("#clientInfo")
. attr ("Value", decodeURI (msg));
}
}
});
}); 
});
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.