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

0

1 Answer 1

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); 
Sign up to request clarification or add additional context in comments.

2 Comments

Could the controller method be called from a non-ajax/plain JS function?
@Clay Banks I updated my answer to accommodate your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.