0

Okay...I am coming from C# MVC using partial views/ajax, etc... Here's what I have: 1 main page with a target ID that renders the default information using a page include.

What I want to do is onclick of a button target the original ID and render a different page as the include. Kind of like RenderPartials in C# MVC.

Can Spring (using Maven) MVC do this or is there a way to go about this that is strait forward?

Thanks,

tereško
  • 58,060
  • 25
  • 98
  • 150
Keltanis
  • 124
  • 1
  • 1
  • 9

1 Answers1

0

You don't need to implement partial views just have an empty div and on click of a button make an ajax request get the content and update the div. something like below.

function button_onclick() {

    var params = {}; //put parameter if any 
      $.ajax({
        headers: { 
        Accept : "text/plain; charset=utf-8","Content-Type": "text/plain; charset=utf-8"},              
        url: "/controller",
        method:"GET",
        data:params,

        success:function(data, textStatus,response) {
            var text = response.responseText;
            if (text == "") {
                return;
            }
            $( "#DIV_ID" ).text(text);
        },
        error: function(response) {
            alert(response);
          // terminate the script
        }
      });
    }
apurvc
  • 740
  • 4
  • 12
  • Okay, so what if I want to return a whole another page, like clicking on tabs would return different information but to the same index page? Does this make sense? The above does work for returning strings and such to ids, but I want click on tab 2 and call information to then replace the DIV with the tab 1 include with the tab 2 include and populate with the new model being passed. – Keltanis Jul 22 '14 at 04:28
  • pretty much same way, make ajax requests and put data in different tabs on tab change events, if using jquery check this http://stackoverflow.com/questions/3641154/jquery-trapping-tab-select-event and http://stackoverflow.com/questions/3718703/get-the-tab-text-on-select-jquery-ui-tabs. You are free to return pretty much any-thing from the controller, any other view(jsp), String, xml, json, image etc.. Checkout http://spring.io/blog/2010/07/22/spring-mvc-3-showcase – apurvc Jul 22 '14 at 04:39