Failed to load resource: the server responded with a status of 406 (Not Acceptable)

Posted by skip on Stack Overflow See other posts from Stack Overflow or by skip
Published on 2012-06-02T10:36:08Z Indexed on 2012/06/02 10:41 UTC
Read the original article Hit count: 216

I am trying to send json data and get back json data as well. I've <annotation-driven /> configured in my servlet-context.xml and I am using Spring framework version 3.1.0.RELEASE. When I send the request the browser tells me that it is not happy with the data returned from the server and gives me 406 error. And when I see the response from the server I see the whole 406 page returned by tomcat 6 server.

I have got following in my pom for Jackson/Jackson processor:

        <!-- Jackson -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.4</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.4</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-xc</artifactId>
        <version>1.9.4</version>
    </dependency>

    <!-- Jackson JSON Processor -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.8.1</version>
    </dependency>

Following is the jquery code I am using to send the json request:

$(function(){$(".sutmit-button").click(function(){

    var dataString=$("#app-form").serialize();
    $.ajax({
        type:"POST",
        url:"apply.json",
        data:dataString,
        success:function(data, textStatus, jqXHR){
            console.log(jqXHR.status);
            console.log(data);
            $('.postcontent').html("<div id='message'></div>");
            $('#message').html("<h3>Request Submitted</h3>").append("<p>Thank you for submiting your request.</p>").hide().fadeIn(1500,function(){$('#message');});
        },
        error:function(jqXHR, textStatus, errorThrown) {
            console.log(jqXHR.status);
            $('.postcontent').html("<div id='message'></div>");
            $('#message').html("<h3>Request failed.</h3>").hide().fadeIn(1500,function(){$('#message');});
        },
        dataType: "json"
    });

return false;});});

Following is the Controller that is handling the request:

@RequestMapping(method = RequestMethod.POST, value="apply", headers="Accept=application/json")
public @ResponseBody Application processFranchiseeApplicationForm(HttpServletRequest request) { 
    //...

    Application application = new Application(...);

    //...
    logger.debug(application);
    return application;
}

I am not able to figure out the reason why I might be getting this error. Could someone help me understand why am I getting the given error?

Thanks.

© Stack Overflow or respective owner

Related posts about JSON

Related posts about jquery-ajax