[英]How to call spring controller method through ajax
Here is my Controller method: 这是我的Controller方法:
@RequestMapping( value={"/home"},params="userAction=loadHomePage",method=Request.POST)
public String viewPage(@ModelAttribute("dataForm") formData, Model model,HttpServletRequest req)throws Exception{
...
}
How to pass the params value through ajax ? 如何通过ajax传递参数值?
Something like this.. Let me know if further guidance is needed.. 这样的事情..让我知道是否需要进一步的指导。
var request= new XMLHttpRequest();
request.onreadystatechange= function(){
if (request.readyState == 4 && request.status == 200) {
}
};
request.open("POST", "/home", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("userAction=loadHomePage");
};
To set the model object: 设置模型对象:
var formData= new FormData();
formData.append('username' , 'payal');
formData.append('id' , 123456);
request.send(formData);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.