开发者

Why is my jquery ajax giving a 406

开发者 https://www.devze.com 2023-03-31 01:35 出处:网络
What is causing this error? I believe it is an incorrect accept header.Shouldn\'t the jquery ajax method set that to the correct value when datatype: \'json\'?

What is causing this error? I believe it is an incorrect accept header. Shouldn't the jquery ajax method set that to the correct value when datatype: 'json'?

406 Not Acceptable

Here's my Spring Controller mapping:

    @Requ开发者_运维问答estMapping(value={"/{ID}"}, method=RequestMethod.GET)
public @ResponseBody Double getRating(@PathVariable(value="ID") final Long id, 
        @RequestParam Long rating) {
    Double ratingResult = rate.get_rating(id);
    return ratingResult;
}

Here's my javascript:

    $.ajax({
    type:'GET',
    url: '/ratings/' + ID + '?rating=' + rating,
    datatype: 'json',
    success: function(data){
        var obj = jQuery.parseJSON( data );
        var ratingResult = obj.ratingResult;
    });

My accept header value is */*


Please verify the server side:

But if you have incorrect response content type it supposed to be application/json, remember what you need to add jackson to your /lib directory.

In your serlvet-name.xml file. And please use firebug to see the json notation if you can catch the object response in your console.

Please verify the client side:

Examine your request headers:

...
dataType: 'json',
...

Accept / Accept: application/json, text/javascript, /; q=0.01 This will explicitly tell the server side that you are expecting JSON.

And... check this: http://www.checkupdown.com/status/E406.html


You can try with 'text/json'...


set you dataType to json and you dont need to do $.parseJSON jquery will parse it for you

$.ajax({
type:'GET',
url: '/ratings/' + ID + '?rating=' + rating,
dataType: 'json',
success: function(data){

    var ratingResult = data.ratingResult;
    //or sometimes you have to do data[0]
    var ratingresult = data[0].ratingResult;
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号