What to do to get JSON in jQuery (Spring)?

Good day to all :)

Trying to make a JSON ajax request in jQuery, the goal is to obtain a collection of elements, but for some reason it does not return anything after success:function(data), tried all browsers and connected library json didn't help. If dataType:text, then comes the code page with which the request was submitted.

I have the whole net is studied on the subject, but the fact that they offer I already have everything, so I suppose that maybe I have something not installed or installed crooked and it doesn't work. Maybe someone had a similar problem, if someone can suggest how to fix it, I would be grateful for help:)
function getData(type) {
 var pagelink = "getData/";
 var url = pagelink +type+ ".html";
 url : url,
 method : "get",
dataType : "json",
 async: false, 
 success : function(data) {

@RequestMapping(value = "/", method = RequestMethod.GET)
 public String home( Model model) {
 return "templeName";
 @RequestMapping(value = "/getData/{type}", method = RequestMethod.GET)
 public @ResponseBody List<string> showData(Model model, @PathVariable("type") String type) {
 List<string> list= new ArrayList<string>(); 
 return list;</string></string></string>
September 19th 19 at 13:11
5 answers
September 19th 19 at 13:13
Thank you all, solved the issue, but not the way I wanted, but still. As it turned out the server-side json request is not formed in the form in which you need to do it manually. That's what happened on the server side
@RequestMapping(value = "/bean")
public class Controller {

 @RequestMapping(value = "/getData", method = RequestMethod.GET)
 public @ResponseBody String showData(Model model) throws JSONException{
 JSONArray userArray = new JSONArray();
 JSONObject userJSON = new JSONObject();
 userJSON.put("id", "1");
 userJSON.put("firstName", "Name");
 userJSON.put("lastName", "LastName");
 userJSON.put("email", "Email");
 return userArray.toString();
September 19th 19 at 13:15
I copied Your code almost one-to-one, but the problem could not reproduce. Everything works as it should: pointed text - got the line that indicated the json Array received. Here is my code:
var url = "bean/getData";
 url: url,
 method: "get",
 contentType: "application/json",
 dataType: "json",
 async: false,
 success: function (data) {

@RequestMapping(value = "/bean")
public class Controller {

 @RequestMapping(value = "/getData", method = RequestMethod.GET)
 List<string> showData() {
 List<string> list = new ArrayList<string>();
 return list;

Try to copy as it is itself and achieve health. Use the debugger of your browser to view Network and. JS source code. If it works, incrementally add its own specifics, checking performance after each change. It is likely that You have made changes in several places, and broke down not because it was switching to json. I in your example just change the dataType between text and json and immediately receive data, respectively, a string or an array.
thank you, I'll know that at least code working, today spent the whole day trying to fix it, created a new project in eclipse and only checked Your code, not working still :( but now it dataType:text if using ModelAndView to forward, climbs in the data code of the page, if Your code return String the value of the collection is that it comes normally. Still, probably something with the settings of Tomcat or eclipse. - Odie_Gleason commented on September 19th 19 at 13:18
September 19th 19 at 13:17
what do you have, in fact, is sent back to the script?))) Time with the text everything works, then the returned dataType does not match the declared in the script
a collection of String trying to send, in the Internet there are examples of this and says that you have to send it via json, they did, but not working. - Odie_Gleason commented on September 19th 19 at 13:20
September 19th 19 at 13:19
And you know that you have from JS is requested address /getData/type.html and the server's listening address /getData/type?
I have in Bina spelled the end of the html in the controller register html the end there is no need, the problem is still not a dataType:text works, then it finds the address on the server:) the problem with the dataType:json, which does not want to come. - Odie_Gleason commented on September 19th 19 at 13:22
September 19th 19 at 13:21
Try add to config:
 <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

Find more questions by tags JSONJavajQuerySpringJavaScript