Help regarding loading JSON using spring annotated controller

Help regarding loading JSON using spring annotated controller

johnnniejohnnnie Posts: 1Questions: 0Answers: 0
edited January 2011 in General
Hello everybody
I do have a following problem. I am building an application using Spring MVC, Hibernate and I would like to use DataTables to display my data. Views are realised through JSP pages, controllers are annotated etc. Whole application is working like a charm except loading JSON from controller (method for creating JSON actually never called).

Here is my jsp:
[code]<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">




JSP Page


var contextPath = "<%= request.getContextPath() %>";

$(document).ready(function() {
$('#controllerGrid').dataTable( {
"bServerSide": true,
"bProcessing": true,
"sAjaxSource": "doajax.do",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
} );



jQuery table



Rendering engine
Browser
Platform(s)
Engine version
CSS grade







[/code]

Here is my controller class for doajax
[code]@Controller
public class doajaxController {

public doajaxController() {
}

@RequestMapping(value="doajax")
public @ResponseBody String doajax() {
String str = "{ \"sEcho\":" + 1 +"," +
" \"iTotalRecords\": 2," +
" \"iTotalDisplayRecords\": 2," +
" \"aaData\": [" +
" [" +
" \"Gecko\"," +
" \"Firefox 1.0\"," +
" \"Win 98+ / OSX.2+\"," +
" \"1.7\"," +
" \"A\"" +
" ]," +
" [" +
" \"Gecko\"," +
" \"Firefox 1.5\"," +
" \"Win 98+ / OSX.2+\"," +
" \"1.8\"," +
" \"A\"" +
" ]" +
" ]" +
"}";

System.out.println("aojcek");

return str;
}
}[/code]

I suppose the problem lies in the fact that doAjax method is never called as "aojcek" is never outputed to console. I am beginner with jQuery, Javascript but fairly experienced java programmer so the problem should be with the way I ask for data.

PS: with txt file containing JSON data placed in web directory, table do get the data :)

I would really appreciate your time and help.

Thanks, Jan Sulin
This discussion has been closed.