title: Ajax call to spring controller callback error function
body: <p>Can you tell me what it's going wrong with the following ajax call to controller ?<br>
  The controller that is called via ajax :</p>
  
  <pre><code>@RequestMapping(value = "/userManagement/loadData.html", method = RequestMethod.POST,produces="text/plain")
  public @ResponseBody String loadData(@RequestBody String jsonData) {
      try {
          Map&lt;String, Object&gt; data = JsonUtils.jsonAsMap(jsonData);
          pageSize = Integer.valueOf(data.get("pageSize").toString());
          pageNumber = Integer.valueOf(data.get("pageNumber").toString());
      } catch (Exception e) {
          return "failure";
      }
      return "success";
  }
  </code></pre>
  
  <p>The ajax function :</p>
  
  <pre><code>function reloadUsers(){
      $.ajax({
          type : "POST",
          cache : false, 
          dataType: 'json',  
          contentType: 'application/json',
          mimeType: 'application/json',
          url : "userManagement/loadData.html",
          data : JSON.stringify({
              pageSize : 10,
              pageNumber : 0
          }),
          success : function(response) {
              if(response.responseText=='true'){
                  console.log('success');
              }else{
                  console.log('server error');
              }
          },
          error : function(jqxhr){
              console.log('error');
              console.log(jqxhr.responseText);
          } 
      });
  }
  </code></pre>
  
  <p><br>
  Now when i execute the ajax call to the controller it always goes on the error function and the <b>jqxhr.responseText</b> is always the value returned by the controller(in this case 'success' or 'failure'.<br><br>
  My question is why is this happening ? <br>
  If i change the controller returned values to "true" or "false" the ajax successfully callback the 'success' function.
  <br>
  I also tried with <code>produces="application/json"</code>and got the same result.</p>