0

I want to get object from controller in ajax method, but I always get error. This is my controller:

@RequestMapping(value = "/getUpdatableCard",method = RequestMethod.GET)
public @ResponseBody Card getUpdatableCard(@RequestParam("card") long id) {
    Card card = null;
    for(int i = 0;i<cards.size();i++) {
        if(cards.get(i).getId()==id) {
            card = cards.get(i);
        }
    }
    System.out.println(card.getExpression());
    System.out.println(card.getCardType().getName());
    System.out.println(id);

    return card;
}

This is my ajax function:

function addAttribute() {
var card = $('#card').val();
$.ajax({
    type:"GET",
    url: contexPath + "/getUpdatableCard",
    data:"card=" + card,
    success:function(data) {
        $("#cardUpdate").modal("show");
        alert(data.id);
    },
    error:function(e) {
        alert('QIRAGI')
    }
});

}

in the web console: status:406 statusText:not acceptable

please help me.

2 Answers2

0

controller

@RequestMapping(value = "/getUpdatableCard/{card}",method = RequestMethod.GET)
public @ResponseBody Card getUpdatableCard(@PathVariable long card) {


    return card;  // break point. you confirm "card". 
}

js

function addAttribute() {
    var card = $('#card').val();
    $.ajax({
        type:"GET",
        url: contexPath + "/getUpdatableCard/" + card,

        success:function(data) {
            $("#cardUpdate").modal("show");
            alert(data.id);
        },
        error:function(e) {
            alert('QIRAGI')
        }
    });
}
0gam
  • 1,343
  • 1
  • 9
  • 21
0

406 Not Acceptable

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

This situation can occur due to many reasons,Either you don't have the correct Jackson library in your classpath, or you haven't used the <mvc:annotation-driven> directive.

Maybe you are missing some of JAR files also.

Spring JSON request getting 406 (not Acceptable)

Community
  • 1
  • 1
tinku
  • 331
  • 4
  • 14