title: How to call a controller from JS so the controller can perform its request mappings?
body: <p>i'm trying to have a JavaScript file call a JavaSpring MVC Controller, then the controller will perform its request mapping functions. </p>
  
  <p>I'm not sure if it is also possible to pass a variable to the controller so it can know which specific mapping to perform. IF one could demonstrate how to do both that would be immensely helpful. If one can simply show me how to call a controller via JS that would be very helpful as well and answer the question. </p>
  
  <p>my controller will look similar to the following:</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/waterquality/scale")
  public class NmWaidsController {
      @RequestMapping(value = {"","/"})
      public String homePageWaids(){
          return "waterquality/scale/calmix";
      }
  </code></pre>
  
  <p>I would like the JS to call this controller. </p>
  
  <p>If possible I would like to do the following, and have the JS pass a variable to the method which would look like the following:</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/waterquality/scale")
  public class NmWaidsController {
      @RequestMapping(value = {"","/"})
      public String homePageWaids(int viewChoice){
          switch(viewChoice){
               case 1:
                   return "waterquality/scale/calmix";
                   break;
               case 2:
                   return "waterquality/scale/caloddo";
                   break;
               case 3:
                   return "waterquality/scale/calstiff";
                   break;
               default:
                   return error;
                   break;
      }
  </code></pre>
  
  <p>Any help would be much appreciated! Thanks in advance!</p>