title: How can I prevent Spring MVC from doing a redirect?
body: <p>I want to handle an AJAX request that updates an entity. I don't really need it to return anything. The problem is that Spring MVC insists on sending a redirect to the same URL (apparently doing its post-redirect-get thing), which the browser dutifully follows.</p>
  
  <p>How can I have a Spring MVC controller method just complete and return something without sending a redirect? Searching on the web only leads to countrless discussions of how to do a redirect, not how to avoid one.</p>
  
  <p>It's a PUT request to <code>http://localhost:9090/pex/api/testrun/f0a80b46-84b1-462a-af47-d1eadd779f59e</code> with these headers:</p>
  
  <pre><code>Host: localhost:9090
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
  Accept: */*
  Accept-Language: de,en-US;q=0.7,en;q=0.3
  Accept-Encoding: gzip, deflate
  Content-Length: 20
  Content-Type: application/json
  Referer: http://localhost:9090/pex/api/testrun/f0a80b46-84b1-462a-af47-d1eadd779f59e/visualizations/common-api?slas=lp,internal,external
  X-Requested-With: XMLHttpRequest
  Connection: keep-alive
  Authorization: Basic xxxx
  </code></pre>
  
  <p>The response has status code "302 Found", no body content and these headers:</p>
  
  <pre><code>Content-Language: "de"
  Content-Length: "0"
  Location: "http://localhost:9090/pex/api/testrun/f0a80b46-84b1-462a-af47-d1eadd779f59e"
  Server: "Jetty(6.1.10)"
  access-control-allow-origin: "*"
  </code></pre>
  
  <p>Here's the Server-side code:</p>
  
  <pre><code>@RequestMapping(value = "/api/testrun/{testrunId}", method = RequestMethod.PUT, consumes = "application/json")
  @ResponseBody
  public Testrun updateOverview(@PathVariable("testrunId") final String testrunId, @RequestBody final String body) {
      return testrunService.updateOverview(testrunId, body);
  }
  </code></pre>
  
  <p>Here's the Javascript code that makes the AJAX call:</p>
  
  <pre><code>$(document).ready(function() {
      $("#update_name_form").submit(function (e) {
          update_testrun($("#name"));
          return false;
      });
  }
  function update_testrun(element) {
      var name = element.attr('name');
      var new_value = element.val().trim();
      var data = {};
      data[name] = new_value;
      $.ajax({url: config.urls.api.testrun + testrun.id,
              type: "PUT",
              contentType: "application/json",
              data: JSON.stringify(data),
              error: function(jqXHR, textStatus, errorThrown) {
                      alert(errorThrown);
              },
              success: function (data, textStatus, jqXHR) {
                      testrun.overview[name] = new_value;
              }
      });
  }
  </code></pre>