Ajax framework-SSM integration framework for ajax Verification
I just learned about the ssm framework and ajax verification is successful.
1. Import the jar package
2. Configure spring-servlet.xml
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJackson2HttpMessageConverter" /> </list> </property> </bean> <bean id="mappingJackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>text/json;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> </bean>
3. Use @ ResponseBody in the Controller to return the json Data Format
@ResponseBody @RequestMapping(value="queryByUser", method=RequestMethod.POST,produces="application/json;charset=UTF-8") public User queryByName(User user,HttpServletRequest request){ User u = userBiz.queryByName(user); return u; }
4. Receive the query results on the page
Function checkUser () {var username = $ ("# username "). val (); $. ajax ({url: "queryByUser", type: "post", data: {"username": username}, dataType: "json", success: function (data) {if (data! = Null) {$ ("# userSpan "). text ("the user name already exists"); $ ("# username "). val ('');} else if (data = null & username! = '') {$ (" # UserSpan "). text (" username available ");}}});}
The implementation result is as follows:
The above section describes how to implement Ajax verification by using the SSM integration framework of the ajax framework. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!