3

I'm trying to use AJAX to load a URL that will return data from my controller, I need the data to be JSONArray but when it makes the call I get a 406 not acceptable error. Is there an yway that I can return this with @ResponseBody? I can't seem to find a solution online. I've already added the Jackson dependency to my project.

My AJAX call:

$.ajax({
    url : '/TeamBravo/graphs/dimple/WEEK',
    success : function(data) {
        var dataForDimpleWeek = data;
    }
});

My Controller:

@RequestMapping("/dimple/{timeScale}")
@ResponseBody
public JSONArray getDimpleData(@PathVariable("timeScale") String timeScale){

    JSONArray tweetsForDimple = new JSONArray();
    if(timeScale.equals("WEEK")){
        tweetsForDimple = getGraphWeekData(); //Returns JSONArray
    }else if(timeScale.equals("MONTH")){
        tweetsForDimple = getGraphMonthData();
    }
    return tweetsForDimple;
}

any help would be most appreciated, thanks.

Highway62
  • 800
  • 1
  • 10
  • 25
  • try adding dataType: "json" to ajax call – Ramesh Kotha Feb 24 '15 at 20:05
  • 1
    I tried that there, it's still giving me the 406 Not Acceptable error – Highway62 Feb 24 '15 at 20:13
  • Does this help? http://stackoverflow.com/questions/23924649/406-error-when-consuming-restful-webservice-in-spring-mvc-project-the-webservic – minion Feb 24 '15 at 21:09
  • `@RequestMapping("/dimple")` `@ResponseBody` `public JSONArray getDimpleData(){` `JSONArray tweetsForDimple = new JSONArray();` `return tweetsForDimple;` `}` Try this simpler version and see if it works or not. – Faraj Farook Feb 24 '15 at 21:27

1 Answers1

1

I actually just answered a post like this, check out my answer here: Converting Java object to JSONObject and transmit it at GET method..

Community
  • 1
  • 1
Nick Cromwell
  • 254
  • 2
  • 5
  • This is not the answer to the question. I downvoted you here and in the other response as you did exactly the same. OP wants to return JSONObject, not convert to GSON. This should be also a comment not a response – Aitor Apr 15 '20 at 08:31