Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This answer is to just confirm that the answer by axtavt works. It took me a minute to realize what he was suggesting, so I thought I'd post a code-snippet to help out anyone coming along behind me. Kudos go to him, though! :)</p> <p><br/></p> <p><strong>MyController.java</strong></p> <pre><code>@Controller public 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.GET, value="/subView" ) public ModelAndView getSubView( Model model ) { model.addAttribute( "user", "Joe Dirt" ); model.addAttribute( "time", new Date() ); return new ModelAndView( "subView" ); } } </code></pre> <p><br/></p> <p><strong>mainView.jsp</strong></p> <pre><code>(...) &lt;script src="http://code.jquery.com/jquery-1.7.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function doAjaxPost() { $.ajax({ type: "GET", url: "subView", success: function(response) { $("#subViewDiv").html( response ); } }); } &lt;/script&gt; &lt;input type="button" value="GO!" onclick="doAjaxPost();" /&gt; &lt;div id="subViewDiv"&gt;&lt;/div&gt; (...) </code></pre> <p><br/></p> <p><strong>subView.jsp</strong></p> <pre><code>(...) &lt;h3&gt; User Access Details &lt;/h3&gt; &lt;p&gt; ${user} accessed the system on ${time} &lt;/p&gt; (...) </code></pre> <p><br/></p> <p>And that's it! A thing of beauty; up to now, doing AJAX in Spring has been a huge pain... parsing big @ResponseBody's, building huge sets of HTML by concatenating stuff in JS... ugh... I can't believe how simple and awesome this approach is -- and wasn't aware of it until just now! :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload