sAjaxSource not working for Java servlet
sAjaxSource not working for Java servlet
I've got a Java servlet that is returning valid JSON data with the content type set to "application/json" (as suggested elsewhere. The JSON data looks like this (saved by going to my servlet's url):
{"sEcho":2,"iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[{"name":"Name1","value":"Value1"},{"name":"Name2","value":"Value2"}]}
My datatables declaration looks like this:
$(function(){
$('#DataTable').dataTable( {
"bProcessing": true,
"sAjaxSource": "http://localhost:8080/test.admin",
"aoColumns": [
{ "mData": "name" },
{ "mData": "value" }
]
} );
});
I can see that the data being returned is correct (breakpoint in my java code), but the datatable on my page just has "Loading..." in it and no data.
If I save the JSON data from the URL to a text file, say ajax.txt, and then set this to be the sAjaxSource, i.e. "sAjaxSource": "ajax.txt", then the page works as expected and my table is populated with two rows.
Anyone got any clues as to what might be the problem? Is it something in my java or something else?
{"sEcho":2,"iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[{"name":"Name1","value":"Value1"},{"name":"Name2","value":"Value2"}]}
My datatables declaration looks like this:
$(function(){
$('#DataTable').dataTable( {
"bProcessing": true,
"sAjaxSource": "http://localhost:8080/test.admin",
"aoColumns": [
{ "mData": "name" },
{ "mData": "value" }
]
} );
});
I can see that the data being returned is correct (breakpoint in my java code), but the datatable on my page just has "Loading..." in it and no data.
If I save the JSON data from the URL to a text file, say ajax.txt, and then set this to be the sAjaxSource, i.e. "sAjaxSource": "ajax.txt", then the page works as expected and my table is populated with two rows.
Anyone got any clues as to what might be the problem? Is it something in my java or something else?
This discussion has been closed.
Replies
Allan
Doh.
i have a question that seems to be near this subject.
I try to use a datatable with a java server. So i read the exemple on this page: http://datatables.net/development/server-side/jsp. I was surprise to see that the code is in a JSP and not in a servlet. By reading this post, i guess it is cross site scripting problems that justify this ?
The Real question is related directly to this subject: do we need to use a special jsp for the datatable server code and to put the view of datatable in another jsp ? i m quite sure it is not possible to put all both on the same jsp. In both case, what is the link for the "sAjaxSource" datatable parameter.
Do we finally need a servlet to make this run with the special jsp
Thanks
This point let me doubtful because in my logical, we call always a servlet declared in the file web.xml.
Is it a special jsp or the same jsp where the widget datatables is ?
++
$(document).ready(function() {
$('#dynamic').html( '');
$('#example').dataTable({
"bProcessing" : true,
"bServerSide": true,
"sPaginationType": "full_numbers",
"sAjaxSource" : "http://localhost/TMC/DataGridJson",
"sServerMethod" : "POST"
});
});
My JSP code is below - just to provide a section for dynamic table :
The call to servlet is not successful. I inserted simple system out print commands to verify the entry into the servlet for both doGet and doPost methods. I gave right URL of the servlet as it prints the system out when URL is submitted in browser.
Can anyone please help me with solving the problem? Is there any syntax issue?