$.getJSON() vs. sAjaxSource

$.getJSON() vs. sAjaxSource

VolvoxeVolvoxe Posts: 4Questions: 0Answers: 0
edited September 2009 in General
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?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Volvoxe,

    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
  • asaasa Posts: 20Questions: 0Answers: 0
    Hi Volvoxe, did you manage to do it with jsp server side ?
    coz i didn't able to do it , maybe because iam new to json thing..
  • VolvoxeVolvoxe Posts: 4Questions: 0Answers: 0
    edited October 2009
    Hi asa!
    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
  • asaasa Posts: 20Questions: 0Answers: 0
    edited October 2009
    Thanx Volvoxe i manage to do it :),Actuallyi take data from database
  • psjandhyalapsjandhyala Posts: 6Questions: 0Answers: 0
    Thanks 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
This discussion has been closed.