Home  >  Article  >  Web Front-end  >  Ajax framework's SSM integration framework implements ajax verification

Ajax framework's SSM integration framework implements ajax verification

亚连
亚连Original
2018-05-22 15:49:282358browse

This article mainly introduces the SSM integration framework of the Ajax framework to implement ajax verification. Friends who need it can refer to it

I just learned the ssm framework and the ajax verification was successful. Share it

1. Import 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 implement the returned 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("用户名已存在");
         $("#username").val(&#39;&#39;);
       }else if(data==null && username !=&#39;&#39;){
         $("#userSpan").text("用户名可用");
       }
      }
     });
   }

The implementation result is as follows Like this:

#The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

NativeajaxWritten pull-up loading example (graphic tutorial)

MUi FrameworkajaxRequest WebService interface instance_AJAX related

Use ajax to submit the form to the database in detail (no refresh)

The above is the detailed content of Ajax framework's SSM integration framework implements ajax verification. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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