Announcement Announcement Module
Collapse
No announcement yet.
MVC Controller and .post Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MVC Controller and .post

    I am trying to post data to the controller using .post to take mew to the next page. I seem to be getting to the controller - the println gets printed but the view doesn't get rendered.(I stay trap on the same I am a newbie so I know there are a milllion things I don't know.

    The web page post
    $.post('/mselectandpay/selection', $('#mselect').serialize() );


    The controller looks like

    @Controller
    @RequestMapping("/mselectandpay")
    public class MselectAndPayController {


    @RequestMapping(value="/selection", method = RequestMethod.POST)
    public ModelAndView about(HttpServletRequest request, ModelMap model) {

    String ID = request.getParameter("sessionID");

    String numMonths = request.getParameter("member_radio");

    System.out.println(ID);

    ModelAndView mav = new ModelAndView("payment_info");
    mav.addObject("sessionID",ID);
    mav.addObject("numMonth",numMonths);

    return mav;

    }

  • #2
    .post is an ajax call and it won't redirect anywhere.

    you should hook up the successfunction and replace some html container in your current page:

    check http://api.jquery.com/jQuery.post/ where you can find further explanations, but basically

    $.post('/mselectandpay/selection', $('#mselect').serialize(),function(data) {
    $('#yourcontainer').html(data);
    });

    Comment


    • #3
      Maybe I am just doing this whole thing incorrectly. I need to basically do a submit so I get my form data back to my controller, construct a new model and return a ModelAndView , get the view (jsp page) rendered and the next web page sent out. I can't use the regular submit because their is a bunch of validation that needs to happen first so I am trying mimic the submit with a .post after the (client side) validation is complete. Obviously this is somehow subverting the MVC. It gets to my controller but the view rendering stuff is not triggered. How should I have done this ?

      Comment


      • #4
        Originally posted by NTG View Post
        Maybe I am just doing this whole thing incorrectly. I need to basically do a submit so I get my form data back to my controller, construct a new model and return a ModelAndView , get the view (jsp page) rendered and the next web page sent out. I can't use the regular submit because their is a bunch of validation that needs to happen first so I am trying mimic the submit with a .post after the (client side) validation is complete. Obviously this is somehow subverting the MVC. It gets to my controller but the view rendering stuff is not triggered. How should I have done this ?
        Well you can handle validation when using a classic html form easily. No need to use ajax.

        Check here http://static.springsource.org/sprin...beanvalidation

        If you still desire to use an ajax approach, my first reply is still valid. On the success function that's called when the ajax call terminates, you have to add to current page DOM the html returned from the controller.

        does that ----> $('#yourcontainer').html(data);

        Comment


        • #5
          I looked a little further and .submit seems to solve the problem.

          Thanks

          Comment

          Working...
          X