Data source JSON objects with Error 403

Data source JSON objects with Error 403

ilpastailpasta Posts: 2Questions: 1Answers: 0
edited March 2016 in Free community support

Hi,
i am trying to implement DataTables in a web application but facing problem at first attempt.

JQuery and HTML is working because the empty table is shown.
JavaScript is:

$('#tableRegisti').DataTable( {
        "ajax": '<?php echo $data['json'] ?>'
        ,"columns": [
                        { "data": "id" },
                        { "data": "cognome" },
                        { "data": "nome" },
                        { "data": "email" },
                        { "data": "id_tipo" },
                        { "data": "id_user" }
                    ]
        ,"order": [[ 4, "desc" ],[ 1, "asc" ]]
    } );

The PHP used return a JSON well formed (successful submitted to parser) like this:

$('#tableRegisti').DataTable( {
        "ajax": '{"data":[{"id":"47","cognome":"Quentin","nome":"Tarantino","email":"quentar@email.it","id_user":"1","id_tipo":"1"},{"id":"48","cognome":"Martin","nome":"Scorsese","email":"marsco@emeil.it","id_user":"1","id_tipo":"2"},{"id":"49","cognome":"Francis","nome":"Coppola","email":"fracop@email.it","id_user":"1","id_tipo":"3"},{"id":"50","cognome":"Stanley","nome":"Kubrick","email":"stakub@email.it","id_user":"2","id_tipo":"1"},{"id":"51","cognome":"Woody","nome":"Allen","email":"woall@email.it","id_user":"2","id_tipo":"2"},{"id":"52","cognome":"Tim","nome":"Burton","email":"timbur@email.it","id_user":"2","id_tipo":"3"},{"id":"53","cognome":"Steven","nome":"Spielberg","email":"stespie@email.it","id_user":"3","id_tipo":"1"},{"id":"54","cognome":"David","nome":"Lynch","email":"davlyn@email.it","id_user":"3","id_tipo":"2"},{"id":"55","cognome":"Clint","nome":"Eastwood","email":"clieas@email.it","id_user":"3","id_tipo":"3"},{"id":"56","cognome":"Frank","nome":"Capra","email":"fracap@email.it","id_user":"1","id_tipo":"1"},{"id":"57","cognome":"Billy","nome":"Wilder","email":"bilwil@email.it","id_user":"2","id_tipo":"2"},{"id":"58","cognome":"Brian","nome":"De Palma","email":"bridep@email.it","id_user":"3","id_tipo":"3"},{"id":"59","cognome":"Ben","nome":"Affleck","email":"benaff@email.it","id_user":"1","id_tipo":"1"},{"id":"60","cognome":"Robert","nome":"Altman","email":"robalt@email.it","id_user":"2","id_tipo":"2"},{"id":"61","cognome":"Buster","nome":"Keaton","email":"buskea@email.it","id_user":"3","id_tipo":"3"}]}'
        ,"columns": [
                        { "data": "id" },
                        { "data": "cognome" },
                        { "data": "nome" },
                        { "data": "email" },
                        { "data": "id_tipo" },
                        { "data": "id_user" }
                    ]
        ,"order": [[ 4, "desc" ],[ 1, "asc" ]]
    } );

The table remains empty and the alert "DataTables warning: table id=tableRegisti - Ajax error. For more information about this error, please see http://datatables.net/tn/7" popup.

Following the istructions i found that response return 403 error.

Test case here : http://live.datatables.net/bihagaje/1/edit?html,js,output

Thanks to all for any suggestions or solutions.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,786Questions: 1Answers: 10,511 Site admin
    Answer ✓

    Don't pass data to the ajax option - pass it through to data. The ajax option tells DataTables where to get the data, data tells it what the data is.

    You should only use one of them.

    Also don't pass in a string - pass in the array of data you want to display - see data.

    Fixed example: http://live.datatables.net/bihagaje/2/edit .

    This question has come up quite a lot recently, is there something in the documentation or examples that you found confusing? It would be useful to know so I can fix it if so.

    Allan

  • ilpastailpasta Posts: 2Questions: 1Answers: 0

    Thanks Allan,
    you was perfectly clear in you explaination.
    It was my mistake to use incorrect option and the documentation is very good.
    Thanks again for the solution.

This discussion has been closed.