JSONP data source for remote domains

JSONP data source for remote domains

hongtaohongtao Posts: 3Questions: 1Answers: 0

Dear developers!
I got errors when using jsonp for remote domains:

The error message:
SyntaxError: missing ; before statement

The warning message:
DataTables warning: table id=table1 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

The javascript:
$(document).ready(function() {
$('#example').dataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "https://xxx.xx.xx.x:8443/jms/dic/test",
"dataType": "jsonp"
}
} );
} );

the reponse from server:

{
"recordsFiltered": 100000000,
"data": [
[
"co1_data0",
"col2_data0"
],
[
"co1_data1",
"col2_data1"
],
[
"co1_data2",
"col2_data2"
]
],
"draw": 1,
"recordsTotal": 100000000
}

Answers

  • hongtaohongtao Posts: 3Questions: 1Answers: 0

    Dear developers! I got errors when using jsonp for remote domains:

    The error message: SyntaxError: missing ; before statement

    The warning message: DataTables warning: table id=table1 - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

    The javascript:

     $(document).ready(function() {
               $('#example').dataTable( {
                   "processing": true, 
                    "serverSide": true, 
                    "ajax": { "url": "https://xxx.xx.xx.x:8443/jms/dic/test", 
                                 "dataType": "jsonp" } 
                    } );
     } );
    
    

    the reponse from server:

    {
        "recordsFiltered": 100000000,
        "data": [
            [
                "co1_data0",
                "col2_data0"
            ],
            [
                "co1_data1",
                "col2_data1"
            ],
            [
                "co1_data2",
                "col2_data2"
            ]
        ],
        "draw": 1,
        "recordsTotal": 100000000
    }
    
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    the reponse from server: [...]

    That isn't JSONP... You need to update the server-side script to return JSONP if you want to use JSONP.

    Allan

  • hongtaohongtao Posts: 3Questions: 1Answers: 0

    Allan, Many thanks! I am able to make it works now.

This discussion has been closed.