title: 'Access-Control-Allow-Origin' error in Spring MVC + Zepto POST
body: <p>I'm trying to POST a JSON object to my Spring MVC controller, but I only receive an <code>Access-Control-Allow-Origin</code> error.</p>
  
  <p>My controller:</p>
  
  <pre><code>@RequestMapping(value= "/add", method = RequestMethod.POST, headers = {"content-type=application/json"})
  public @ResponseBody Reponse addUser(Model model, @RequestBody @Valid @ModelAttribute("user") User user, BindingResult result) {
      if (result.hasErrors()) {
          Reponse error = new Reponse();
          // etc......
          return error;
      } else {
          return service.addUser(user);
      }
  }
  </code></pre>
  
  <p>My Zepto POST:</p>
  
  <pre><code>this.addUser = function (valeur, callback) {
      $.ajax({
          type: 'POST',
          url: 'http://127.0.0.1:8080/AgenceVoyage/user/add',
          data: JSON.stringify({"mail" : "toto@toto.fr" , "password" : "titi"}),
          dataType: "json",
          contentType: "application/json",
  
          success: function(data) {
              if(data.reponse == "OK") {
                  window.location = "main.html";
              } else {
                  alert("PROBLEM");
              }
          },
  
          error: function(xhr, type) {
              alert("ERROR");
          }
      });
  };
  </code></pre>
  
  <p>I tried with no stringify in POST request, with no headers in <code>@RequestMapping</code>.</p>
  
  <p>My result:</p>
  
  <blockquote>
    <p>OPTIONS <a href="http://127.0.0.1:8080/AgenceVoyage/user/add" rel="nofollow">http://127.0.0.1:8080/AgenceVoyage/user/add</a> No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin '<a href="http://localhost:9000" rel="nofollow">http://localhost:9000</a>' is therefore not allowed
    access. zepto.min.js:2 XMLHttpRequest cannot load</p>
  </blockquote>