sAjaxSource question

sAjaxSource question

mv5492mv5492 Posts: 10Questions: 0Answers: 0
edited December 2009 in General
Hi, I've decided to invest my time into this pretty cool plugin and really want to work through my novice issues.

I need to populate the data table with a one time grab. This works fine when the JSON is in a static file. But when I generate the JSON from a database call and print it to stdout I get nothing into the grid. I'm not using PHP. I'm using CGI.pm, but i'm not printing the header, so it's the exact same output that I have in my static input file.

JSON (as output when run direct from commandline):
{ "aaData": [
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "ACCT", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "ACCT_SGMNT_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "ACCT_SUBSRPTN_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "ACCT_TYPE_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "BL_STMNT_ACTVT_ARPU", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "CMBND_ACCT_ELGBLY_TRANS", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "FAN_INFOR_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "NBI_LOCL_MKT_PRD_XREF", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "PRD", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "PRD_RATE", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "PRD_TYPE_AVT", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "PRTN_OWNR", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "PRTY_ACCT_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "PRTY_AGNT", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "PRTY_NM", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "PRTY_SUBSRPTN_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SGMNT_CLSFCTN_AVT", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN_ACTVT_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN_CGSA_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN_CONTRCT_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN_GRP_NBR_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN_SRV_ACCS_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN_STS_AVT", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN_STS_HIST", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUBSRPTN_STS_RSN_AVT", "" ],
[ "ARMERC01_ARC3_EDWTT_XXX01", "EDWDB", "SUB_TECH_TYPE_HIST", "" ]
] }

var newTable = $(document.createElement('')).attr({'id': 'tableOne', 'class': 'conmgmt'}).append(' ArchiveID DatabaseName TableName Select Statement ArchiveID DatabaseName TableName Select Statement ');

$('body').append(newTable);

$(document).ready( function () {
$('#tableOne').dataTable( {
"bServerSide": false,
"bProcessing": false,
"sAjaxSource": './JSON.cgi'
} );
} );

I get something that looks like this (no styling yet):

Show [10] entries
Search: [ ]
ArchiveID DatabaseName TableName Select Statement
No matching records found
ArchiveID DatabaseName TableName Select Statement

Showing 0 to 0 of 0 entries

Any idea what I'm doing wrong?

Thanks,
Mike

Replies

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Hi Mike,

    I'm going to take a bit of a guess and say that you are a shell person? :-). ./JSON.cgi would be how you run the script on the cli, but typically wouldn't be how you do it from a web-browser. What you need is the URL for the script, and just put that in there - the web-server will do the actual execution of the script. If you can get the URL and just stick that into the browser, and it loads the JSON as text - then that is the UR you want for sAjaxSource.

    Using Firebug is also helpful for seeing what is going on with Ajax requests. One other thing is that you might need to output a content-type (text/plain would do) in your script, otherwise you might be getting "premature end of script headers".

    Let us know if that helps or not - if not, then could you possibly provide a link to a page showing the problem?

    Thanks,
    Allan
  • mv5492mv5492 Posts: 10Questions: 0Answers: 0
    Thanks Allan, specifying the URL to the CGI worked. But just dumping the JSON is not enough. For perl CGI scripts the header must alo be provided:

    $q = new CGI;
    print $q->header;

    Mike
  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Hi Mike,

    Yup the content type echos out the MIME content-type, which is required for the browser to know what kind of data it is. Good to hear you got this fixed :-)

    Regards,
    Allan
This discussion has been closed.