How to pass Json object from ajax to spring mvc controller?

前端 未结 5 1253
小蘑菇
小蘑菇 2020-12-01 04:48

I am working on SpringMVC, I am passing data from ajax to controller but i got null value in my controller please check my code below

function searchText()
{         


        
5条回答
  •  渐次进展
    2020-12-01 05:21

    u take like this 
    var name=$("name").val();
    var email=$("email").val();
    
    var obj = 'name='+name+'&email'+email;
      $.ajax({
       url:"simple.form",
       type:"GET",
       data:obj,
       contentType:"application/json",
       success:function(response){
      alert(response);
      },
      error:function(error){
      alert(error);
      }
    });
    

    spring Controller


    @RequestMapping(value = "simple", method = RequestMethod.GET)
    public @ResponseBody String emailcheck(@RequestParam("name") String name, @RequestParam("email") String email, HttpSession session) {
    
        String meaaseg = "success";
        return meaaseg;
    }
    

提交回复
热议问题