Using fnServerData fails with jQuery 1.5.1

Using fnServerData fails with jQuery 1.5.1

whobutsbwhobutsb Posts: 15Questions: 0Answers: 0
edited March 2011 in General
Hello all!
So I've been working away with DataTables and specifically the fnServerData function. What i'm looking to do is return a set of results from the server and have it render in the DataTables.

So here is my setup:
DataTables JS:
[code]
$(function(){

$('table').dataTable({
'bJQueryUI': true,
'bProcessing': true,
'bServerSide': true,
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
'dataType' : 'json',
'type' : 'POST',
"url" : 'http://icarus/SF2/AJAX/ajax_tables/guest_surveysessions_table_data/2345',
"data" : aoData,
"success" : fnCallback
} );
}
});

});
[/code]

The truncated returned results:
[code]
{
"sEcho": 1,
"iTotalRecords": 114,
"iTotalDisplayRecords": 114,
"aaData": [
[
"Fri, March 4, 2011, 10:24 AM",
"Mon, March 15, 2010, 8:52 PM",
"Fare Rewards Guest Survey",
"Hemenway's",
"Survey Session Details<\/a>"
],
[
"Fri, March 4, 2011, 8:00 AM",
"Fri, March 4, 2011, 10:01 AM",
"Fare Rewards Guest Survey",
"Hemenway's",
"Survey Session Details<\/a>"
],
...
]
}
[/code]

The JSON is valid I ran it through jsonlint.com, and it came back with out a problem. The issue was when I use jQuery 1.5.1 being called with the Google JS Library script. It comes back with this error:

[code]Uncaught SyntaxError: Unexpected token :[/code]

But if I roll back to jQuery 1.4.4, I don't have any issues and it works fine. Anybody have any insight on why this would happen?

Thank you for the help!

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Are you using the jQuery validation plug-in? That has issues with jQuery 1.5 Ajax. You need to update to the very latest version if so.

    Allan
  • whobutsbwhobutsb Posts: 15Questions: 0Answers: 0
    You sir are correct! I would've never guessed that! Thank you very much. jQuery 1.5.1 is working fine now.

    I had this jquery plugin enabled:
    http://bassistance.de/jquery-plugins/jquery-plugin-validation/
  • metuck2metuck2 Posts: 2Questions: 0Answers: 0
    edited January 2012
    I am having the same problem but I am using the newest version of JQuery 1.7.1.

    [code]
    fnServerObjectToArray = function ( aElements )
    {
    return function ( sSource, aoData, fnCallback ) {
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": function (json) {
    var a = [];
    for ( var i=0, iLen=json.aaData.length ; i
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Are you also using the newest version of the validation plug-in for jQuery?

    Allan
  • little_heroinelittle_heroine Posts: 6Questions: 0Answers: 0
    i am wondering why, in my code my fnServerdata() can not been called, likely my browser cannot support such method. i use firefox11.0, firebug1.9.1, test step by step

    here is my code:
    [code]
    $(document).ready(function() {
    $('#hosts').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource":'/hosts',
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    alert("");
    aoData.push({ "name": "name", "adresss": "adresss", "comment": "comment"});
    $.ajax({
    'dataType': 'json',
    'type': 'post',
    "url": sSource,
    "data":aoData,
    "success": fnCallback
    }
    });
    }
    });
    });
    [/code]
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Looks to me that you have a syntax error on line 15. Does the Javascript console in your browser not show an error?

    Allan
  • little_heroinelittle_heroine Posts: 6Questions: 0Answers: 0
    thanks a lot, yes it is that problem. i saw it this time and correct it.
    but there is another error to show
    [code]
    oColumn is undefined
    [Break On This Error]

    oSettings.aaSorting[i][1] = oColumn.asSorting[0];
    [/code]

    what will be the reason? the data ?
  • little_heroinelittle_heroine Posts: 6Questions: 0Answers: 0
    I have got it . that i need to give a structure for my datatable :host.
    and i do this with aoColumnDefs. Now it works.hah
    hah thank you /smile
  • rovi22rovi22 Posts: 2Questions: 0Answers: 0
    edited May 2012
    I have a similar problem to the original poster except i have no reference to jQuery validation. I am using jsonp though. would this make a difference?

    Note: this setup works fine if my source is not a cross domain call.

    Code:
    [code]

    Test



    var asInitVals = new Array();
    $(document).ready(function (){
    var oTable = $('#certifications').dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "http://localhost:7069/Partner/List?accountType=OEM",
    "fnServerData": function (sSource, aoData, fnCallback){
    $.ajax({
    "dataType": 'jsonp',
    "url": sSource,
    "data": aoData,
    "type": "post",
    "success": fnCallback
    });
    }
    });
    });


    [/code]

    Update: (figured it out) It helps when the endpoint supports jsonp.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > Update: (figured it out) It helps when the endpoint supports jsonp.

    heh - good to hear you got it working.

    Allan
This discussion has been closed.