Home > Web Front-end > JS Tutorial > How to implement ajax verification function using SSM integration framework

How to implement ajax verification function using SSM integration framework

php中世界最好的语言
Release: 2018-03-31 17:29:41
Original
1809 people have browsed it

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 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>
Copy after login

3.

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;
   }
Copy after login

4. The page receives the result of

query

function 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("用户名可用");
       }
      }
     });
   }
Copy after login
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 upload


How to use Ajax to dynamically load data

The 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template