weixin_33725515 2017-03-24 08:46 采纳率: 0%
浏览 19

Ajax Email Pass Spring MVC

How to pass email id via ajax call (not as string), i need to catch that email parameter in spring controller.

$.ajax({
        type : "POST",
        contentType : "application/json",
        data: data,
        dataType: "text",
        url : "<%=request.getContextPath()%>/methodName";,
        success : function(data){

        }
        });

Java code:

@RequestMapping(value="/methodName/{email}", method =RequestMethod.POST,produces="application/json")
    @ResponseBody
    public String resetPassword(@PathVariable(value = "email") String email) throws Exception{
        //do something
        return "success";
    }
  • 写回答

1条回答 默认 最新

  • weixin_33749131 2017-03-24 10:26
    关注

    The below code did the trick.

    $.ajax({
            type : "POST",
            data: { 
                'email': email
            },
            url : "<%=request.getContextPath()%>/methodName";,
            success : function(data){
    
            }
            });
    
    @RequestMapping(value="/methodName", method =RequestMethod.POST)
        @ResponseBody
        public String resetPassword(@RequestParam(value = "email") String email) throws Exception{
            //do something
            return "success";
        }
    
    评论

报告相同问题?