简体   繁体   English

如何通过Ajax调用Spring Controller方法

[英]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.

相关问题 如何显示从AJAX调用Spring控制器方法的响应? - How to show response from AJAX call to Spring controller method? 如何使用Jquery AJAX调用Spring控制器方法 - How do I call a Spring controller method with Jquery AJAX 如何在jquery ajax成功方法中调用spring controller - how to call spring controller in jquery ajax success method 无法通过Rails中的Ajax调用控制器方法 - Unable to call controller method through ajax in rails Ajax请求 - 在Spring Controller上调用不同的方法 - Ajax Request - Call different method on Spring Controller 无法调用控制器方法,使用Spring MVC进行Ajax调用 - Couldnt call controller method , ajax call with spring mvc 如何将@ModelAttribtue传递给Controller并调用POST方法以使用Ajax调用在Spring MVC中插入数据 - How to pass @ModelAttribtue to Controller and call POST method to insert the data in spring mvc using ajax call 无法通过Ajax调用命中Spring MVC控制器 - Unable to hit spring mvc controller through ajax call 通过Ajax调用提交JSON数据在Spring Controller中不起作用 - submitting json data through ajax call not working in spring controller 如何通过Ajax调用将动态ceated表行列的数据值从JSP传递到Spring控制器 - How to Pass dynamic ceated table row column Data values from JSP to Spring controller through ajax call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM