jquery Ajax transfer view in Spring MVC

Source: Internet
Author: User

SPRINGMVC Project encountered to use the Jqueryajax to the foreground to pass the dynamic table needs, the original practice is to receive data in JS and then splicing into a table and then to the JSP display, later on this foreign site saw the following use of the "template" design, feel very reasonable, I tested a bit , think more than before JS splicing easy to use a lot, greatly reduce the pressure of JS. I just copied the original author's answer (the answer is really detailed), record it, feel that I grew up again.

Mycontroller.java

@Controllerpublic  class MyController {     @RequestMapping ( method= Requestmethod.get, value= "/mainview"  )     public ModelAndView  Getmainview ( ... )  {                 /* do all your normal stuff here to build  your primary non-ajax view         * in  the same way you always do          */                  }    /* this is the conroller ' s part of the magic;  i ' m just using a simple get but you     *  could just as easily do a post here, obviously     */     @RequestMapping ( method=requestmethod, value= "/subview"  )     public  Modelandview getsubview ( Model model )  {         model.addattribute (  "User",  "joe dirt"  );         model.addattribute (  "Time",  new date ()  );         return new modelandview (  "SubView"  );     }}

mainview.jsp

(...) <script src= "Http://code.jquery.com/jquery-1.7.1.min.js" ></script><script type= "text/ JavaScript ">    function doajaxpost ()  {         $.ajax ({            type:  "GET",             url:  "SubView",             success: function (response)  {                 $ ("#subViewDiv"). HTML (  response );            }         });     }</script><input type= "button"  value= "Go!"  onclick= "Doajaxpost ();"  /><div id= "Subviewdiv" ></div> (...)

subview.jsp

(...) 


Here is the original address:

Http://stackoverflow.com/questions/4816080/how-to-render-a-view-using-ajax-in-spring-mvc


Thank the Great God! And thanks to my great far elder brother!





This article is from the "Java Program Ape Blog" blog, be sure to keep this source http://chengxuyuan.blog.51cto.com/5789198/1598960

jquery Ajax transfer view in Spring MVC

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.