How to submit spring form in ajax(jquery) with modelAttribute

前端 未结 2 1370
不知归路
不知归路 2021-02-01 08:20

I am new to Spring MVC. I have a form like this,

and a co

相关标签:
2条回答
  • 2021-02-01 08:45

    your ModelAttributes are not populated as you are not passing any params to server.Form data has to be posted to server

    $.post('myaction.htm', $('#formid').serialize()) to send ajax post request.

    0 讨论(0)
  • 2021-02-01 08:50

    You need to post the data. The way I typically do it is using the following.

    var str = $("#myForm").serialize();
    
    $.ajax({
        type:"post",
        data:str,
        url:"/myaction.htm",
        async: false,
        dataType: "json",
        success: function(){
           alert("success");
        }
    });
    
    0 讨论(0)
提交回复
热议问题