Data not showing when doing a very simple ajax example.

Data not showing when doing a very simple ajax example.

mastermgwmastermgw Posts: 2Questions: 0Answers: 0
edited October 2009 in General
I've search the forum but nothing seems to be dead on.

Environment.
I am running a coldfusion back end.
I have a CMS running ( bluApple ).
I am using FF, but the problem is not browser specific.

Example URL: http://dev14.wowcorefive.com/index.cfm?ba=a_productslist
note, I have disabled security for this URL. Once I fix the issue it will be behind
closed doors and if you need to see the page you will need to contact me directly.

The jQuery Code:
[code]

$(function(){

$('#list').dataTable( {
"sAjaxSource": '#actionPage#?action=getproducts',
"aoColumns": [
"ID",
"ACTIVE",
"NAME",
"SECTION",
"DETAIL",
"LASTMODIFIED",
"CREATEDATE"
],
"bJQueryUI": true,
"sPaginationType": "full_numbers"
} );
});

[/code]

Table Code:
[code]



ID
Active
Name
Section
Detail
Last Modified
Create Date






[/code]

Ajax Code Returned from my URL:
[code]
{"aaData":["ACTIVE":"1","CREATEDATE":"2009-02-15 20:44:57.0","DESCRIPTION":"homepage content","DETAIL":"Put some content here.","ID":"1","LASTMODIFIED":"2009-08-19 15:48:41.0","NAME":"homepagecontent","SECTION":"home"],["ACTIVE":"1","CREATEDATE":"2009-10-20 08:19:46.0","DESCRIPTION":"test","DETAIL":"test","ID":"23","LASTMODIFIED":"2009-10-20 08:19:52.0","NAME":"test","SECTION":"test"]}
[/code]

History:
At first attempt, I got a js error popup saying that my columns did not match. This is because your JSON needs to be very specific. I have a backend function QueryTOJSON which converts a coldfusion query to a JSON object with used "{" instead of "[" as a delimeter for a new row. Standard JSON supports this .. but your ajax function did not.. So I just tweaked the function a little bit and that made that error go away. Bottom line is was a json formatting issue.

Once that issue was resolved, I am left with this blank and puzzling issue. I get no JS error. The page loads fine.
I am using the JQUERYUI Themeroller setup. But I get zero data populated into my table. I am not even trying to do anything complex or complicated. I am doing a very simple and basic example. I have studied your documentation. It does not appear that I am doing something wrong.

Initially, I did not have the columns specified in the Init. But I found a post that might suggest that they needed to be there. This did not fix anything. Nor did it make any difference at all.

Am I missing something? I know this product works! I have seen several examples on the website. I do not appear to be doing anything different. I need help.

About Me:
I am a developer of 12+ years. I am profecient in CF, JS, and several other web languages.
I am trying to get a project done this week and I think it would really impress my client if I
had these datatables working.

Please, I know this is not a commercial product, But I need commercial support and am willing
to pay for it.

Thanks,
Marco G. Williams
somethingJava, LLC
714-330-1296

Replies

  • mastermgwmastermgw Posts: 2Questions: 0Answers: 0
    I found the issue. The problem was with my JSON code.. the component that exports from my CF query to JSON format was including field names. I have modified the code to export the data in the appropriate fashion.. Below you will see the difference between what I had and what the new code is...

    OLD JSON OUTPUT
    [code]
    {"aaData":["ACTIVE":"1","CREATEDATE":"2009-02-15 20:44:57.0","DESCRIPTION":"homepage content","DETAIL":"Put some content here.","ID":"1","LASTMODIFIED":"2009-08-19 15:48:41.0","NAME":"homepagecontent","SECTION":"home"],["ACTIVE":"1","CREATEDATE":"2009-10-20 08:19:46.0","DESCRIPTION":"test","DETAIL":"test","ID":"23","LASTMODIFIED":"2009-10-20 08:19:52.0","NAME":"test","SECTION":"test"]}
    [/code]

    NEW JSON OUTPUT
    [code]
    { "aaData":[
    ["1","2009-02-15 20:44:57.0","homepage content","Put some content here.","1","2009-08-19 15:48:41.0","homepagecontent","home"],
    ["1","2009-10-20 08:19:46.0","test","test","23","2009-10-20 08:19:52.0","test","test"]
    ]}

    Works perfectly now.

    [/code]
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    Hi Marco,

    Great to hear you found and fixed the problem. You might be interested in using http://www.jsonlint.com in future which is an excellent took for testing the validity of a JSON string.

    Other other thing I noticed from your post, you aoColumns initialisation looks a bit odd (I'm slightly surprised DataTables doesn't chock on it actually). aoColumns is an array of objects, not an array of strings like you have. You can see an example here: http://www.datatables.net/usage/columns#sTitle

    Regards,
    Allan
This discussion has been closed.