1
[{"name":"aaa","firstname":"bbb","lastname":"ccc"},
{"name":"qqq","firstname":"eee","lastname":"mmm"},
{"name":"www","firstname":"ooo","lastname":"lll"}]

I am making ajax request to server, its returning the above json data.But i >am getting the json parse error

$(document).ready(function() {
    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
                "url": "http://example",
                "dataType": "jsonp",
        "columns": [
                { "data": "name"},
                { "data": "firstname" },
                { "data": "lastname" }
            ]
            }
        } );
});
7
  • is this the right way to assign columns ?datatables.net/examples/ajax/objects.html Commented Feb 12, 2015 at 8:56
  • @RohanKumar, well - he is getting a result back, and using jsonp .... So no, has nothing to do with Same-origin policy. Commented Feb 12, 2015 at 8:57
  • Yes, it looks much better now :) have deleted the answer. Commented Feb 12, 2015 at 9:13
  • DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see datatables.net/tn/1 Commented Feb 12, 2015 at 9:22
  • The data you have is not JSONP. Commented Feb 12, 2015 at 9:57

1 Answer 1

1

Your ajax attribute should not contain the column attribute.:

Code:

$(document).ready(function() {
    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
                "url": "http://example",
                "dataType": "jsonp"
        },
        "columns": [
                 { "data": "name"},
                 { "data": "firstname" },
                 { "data": "lastname" }
            ]
        } );
});
Sign up to request clarification or add additional context in comments.

3 Comments

If i remove jsonp, i am getting Same origin policy error
@GirishMahindrakar, ok for same origin policy can be added like that, however your ajax and columns where overlapping which I have shown in the answer
+1. Good spot. I also think this is the correct answer. @GirishMahindrakar, you have simply malformed initialization options :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.