Home >Web Front-end >JS Tutorial >How to implement ajax verification function using SSM integration framework
This time I will show you how to implement the ajax verification function using the SSM integration framework. What are the things to note when using the SSM integration framework to implement the ajax verification function? The following is a practical case. Let’s take a look. one time. I just learned the ssm framework and the ajax verification was successful. Share it
1. Import the jar package2. 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>
Use @ResponseBody in controller to return 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;
}
queryfunction checkUser(){
var username=$("#username").val();
$.ajax({
url:"queryByUser",
type:"post",
data:{"username":username},
dataType:"json",
success:function(data){
if (data!=null ) {
$("#userSpan").text("用户名已存在");
$("#username").val('');
}else if(data==null && username !=''){
$("#userSpan").text("用户名可用");
}
}
});
}
The implementation result is as follows:
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Ajax+Spring to implement file uploadHow to use Ajax to dynamically load dataThe above is the detailed content of How to implement ajax verification function using SSM integration framework. For more information, please follow other related articles on the PHP Chinese website!