最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to call the spring controller method from form using java script or Jquery - Stack Overflow

programmeradmin3浏览0评论

Hai i tried calling the controller using

document.forms[0].value = "getSignFaces";

document.forms[0].submit();

But its not calling method in controller

@RequestMapping(value=signFaces.do, method=RequestMethod.POST , params ="getSignFaces")

    public String getSignFaces(Model model,@ModelAttribute(HBMSWebConstants.MODEL_SIGN_DETAILS) HBMSSessionDataWO sessionData,
@ModelAttribute SignDetailsForm form,HttpServletRequest request, 
HttpServletResponse response,@RequestParam String noOfFaces,

I need to send the noOfFaces to this method.

Some how it is failling. Please let me know if i am missing any thing

Hai i tried calling the controller using

document.forms[0].value = "getSignFaces";

document.forms[0].submit();

But its not calling method in controller

@RequestMapping(value=signFaces.do, method=RequestMethod.POST , params ="getSignFaces")

    public String getSignFaces(Model model,@ModelAttribute(HBMSWebConstants.MODEL_SIGN_DETAILS) HBMSSessionDataWO sessionData,
@ModelAttribute SignDetailsForm form,HttpServletRequest request, 
HttpServletResponse response,@RequestParam String noOfFaces,

I need to send the noOfFaces to this method.

Some how it is failling. Please let me know if i am missing any thing

Share Improve this question edited Jun 26, 2014 at 14:47 secretformula 6,4324 gold badges34 silver badges56 bronze badges asked Jun 26, 2014 at 13:50 user2593318user2593318 351 gold badge2 silver badges7 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 2

I think you can try using an ajax call to do the post to the controller.

as an example:

var jsonfile= {json:JSON.stringify(contents)};
$.ajax({
type:'POST',
url: "/yourcontrollermapping/signFaces.do
data: jsonfile,
dataType: "json"
});

and then your controller method:

@Controller
@RequestMapping("/yourcontrollermapping"
public class YourController(){
@RequestMapping(value = "/signFaces.do, method = RequestMethod.POST)
public void getSignFaces(@RequestParam("json) String json){
//stuff you want to do
}
}

If you wanne do it javascript native you can :

var jsonfile= {json:JSON.stringify(contents)};
var r = new XMLHttpRequest(); r.open("POST", "yourcontrollermapping/signFaces.do", true); r.onreadystatechange = function () {  if (r.readyState != 4 || r.status != 200) return;   console.log(r.responseText); }; r.send(jsonFile); 
发布评论

评论列表(0)

  1. 暂无评论