$.getJSON() vs. sAjaxSource
$.getJSON() vs. sAjaxSource
Hi!!
Can you help me figure out the diference beetween $.getJSON vs. sAjaxSource?
I get a JSON source from DB
[code]
var laTabla;
$(document).ready(function() {
/*This does work, even fnRender */
$.getJSON( 'ajax/getdata.jsp', null, function( json ) {
laTabla= $('#example').dataTable(json);
} );
});
[/code]
but when using SAME source, different call, it won't work, I get the error "nThs is null".
[code]
var laTabla;
$(document).ready(function() {
/*This does NOT work */
laTabla= $('#example').dataTable( {
"sAjaxSource": "ajax/getdata.jsp"
} );
});
[/code]
The reason I want to use sAjaxSource is to be able to use a json source to example http://datatables.net/examples/server_side/row_details.html
Any suggestions, ideas, SAMPLES?
Can you help me figure out the diference beetween $.getJSON vs. sAjaxSource?
I get a JSON source from DB
[code]
var laTabla;
$(document).ready(function() {
/*This does work, even fnRender */
$.getJSON( 'ajax/getdata.jsp', null, function( json ) {
laTabla= $('#example').dataTable(json);
} );
});
[/code]
but when using SAME source, different call, it won't work, I get the error "nThs is null".
[code]
var laTabla;
$(document).ready(function() {
/*This does NOT work */
laTabla= $('#example').dataTable( {
"sAjaxSource": "ajax/getdata.jsp"
} );
});
[/code]
The reason I want to use sAjaxSource is to be able to use a json source to example http://datatables.net/examples/server_side/row_details.html
Any suggestions, ideas, SAMPLES?
This discussion has been closed.
Replies
Here is an example showing how to use sAjaxSource: http://datatables.net/examples/data_sources/ajax.html
Note that the returned object is only expecting a single property in the array (aaData) rather that a full DataTables initialisation object - which will not work (as you are seeing!). If you want to load fnRender etc from the AjaxSource then, the $.getJSON() call is the correct way to do it.
Regards,
Allan
coz i didn't able to do it , maybe because iam new to json thing..
As Allan kindly pointed, with AjaxSource you can only fetch the aaData array, thus I must reply:
"NO, I didn't managed to use AjaxSource to build a table from scratch"
BUT WAIT!!!
Nevertheless I DO use Ajaxsource to populate a table in our intranet. This is how I did it:
a) Setup a table based on Allan's usage example http://datatables.net/usage/
[code]
Rendering engine
Browser
Platform(s)
Engine version
CSS grade
[/code]
b) Use Allan's json sample file http://datatables.net/examples/examples_support/json_source.txt and rename it, say, asa_dinamyc.jsp
c) Fire your table using AjaxSource:
[code]
$(document).ready(function() {
$('#asatable').dataTable( {
"sAjaxSource": 'asa_dinamyc.jsp'
} );
} );
[/code]
All there is left to do now: Have java to provide the data :)
Regards,
Volvoxe
with the simple steps which you mentioned above I followed them and I implemented same thing in my project , it is working great.
Thanks
psjandhyala