"Internal Server Error" on POST ajax and Data

"Internal Server Error" on POST ajax and Data

luernesluernes Posts: 4Questions: 1Answers: 1

Hi every body, i'm really new working with Datatables, and before to asking about, i was reading a lot about this error on the post. and follow the suggestions, but error its the same "Internal Server Error" every thing working fine when i used get, but i need more columns on my table, so i need use post.

this is my table on html table

Date Added First Name Last Name Loan Follow up Time Old Days State DXStatus DXR-Code IsESigned

this is my script on a page.

    var pending = $("#pending");

    tblpending = pending.DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            "url": "mydata",
            "type": "post",
            data: function ( json ) {
                return  JSON.stringify( json );
            }
        },
        rowId: 'id',
        order: [[1, 'desc']],
        columns: [
            {"data": "id"},
            {"data": "DateApplicationReceived"},
            {"data": "FirstName"},
            {"data": "LastName"},
            {"data": "DisplayNumber"},
            {"data": "FollowUpDateTime"},
            {"data": "DaysOld"},
            {"data": "State"},
            {"data": "tbStatus"},
            {"data": "DxRequestCode"},
            {"data": "tbIsESigned"},
            {
                "defaultContent": "<a id='edloan' href='#' data-toggle='modal' data-target='#editLoanModal' >" +
                "<i class='fa fa-pencil-square-o text-black'></i></a>"
            }
        ],
        aoColumnDefs: [
            {
                "targets": 0,
                "searchable": false,
                "orderable": false,
                "class": "dt-center",
                "render": function (data, type, full, meta) {
                    return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
                }
            },
            {
                "targets": 6,
                "searchable": false,
                "class": "dt-center"
            },
            {
                "targets": 7,
                "class": "dt-center"
            },
            {
                "targets": 8,
                "searchable": false,
                "class": "dt-center",
                "orderable": false
            },
            {
                "targets": 9,
                "searchable": false,
                "class": "dt-center",
                "orderable": false
            },
            {
                "targets": 10,
                "searchable": false,
                "class": "dt-center",
                "orderable": false
            },
            {
                "targets": 11,
                "searchable": false,
                "class": "dt-center",
                "orderable": false
            }
        ]
    });

I also want to know if the order where you include js on your page could be responsible of that behavior?

In my case all js where called before that script.

Also another tips could be, that in my case DataTable definition it's out off document.ready() and i'm, not too clear where to define it, because with get its working fine in both places.

i'm working with laravel.

sorry for my rookies questions.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    For an internal server error, the first place to look is at the server's error log. It will normally contain some kind of information that will state what the issue is. The issue won't be Javascript as such (although that might trigger the error).

    Allan

  • luernesluernes Posts: 4Questions: 1Answers: 1

    Hi allan, and thanks for your quick answer. I'm receiving a typical "Warning: Ajax error that you refer in https://datatables.net/manual/tech-notes/7". I check my data and i consider is in right format. but problem it's same. Internal error it's console message, but it's happen the same when i make upload to my host, so i considering it's other my problem, any subjection.

    {"draw":1,"columns":[{"data":"id","name":"","searchable":false,"orderable":false,"search":{"value":"","regex":false}},{"data":"DateApplicationReceived","name":"","searchable":true,"orderable":true,"search":{"value":"","regex":false}},{"data":"FirstName","name":"","searchable":true,"orderable":true,"search":{"value":"","regex":false}},{"data":"LastName","name":"","searchable":true,"orderable":true,"search":{"value":"","regex":false}},{"data":"DisplayNumber","name":"","searchable":true,"orderable":true,"search":{"value":"","regex":false}},{"data":"FollowUpDateTime","name":"","searchable":true,"orderable":true,"search":{"value":"","regex":false}},{"data":"DaysOld","name":"","searchable":false,"orderable":true,"search":{"value":"","regex":false}},{"data":"State","name":"","searchable":true,"orderable":true,"search":{"value":"","regex":false}},{"data":"tbStatus","name":"","searchable":false,"orderable":false,"search":{"value":"","regex":false}},{"data":"DxRequestCode","name":"","searchable":false,"orderable":false,"search":{"value":"","regex":false}},{"data":"tbIsESigned","name":"","searchable":false,"orderable":false,"search":{"value":"","regex":false}},{"data":11,"name":"","searchable":false,"orderable":false,"search":{"value":"","regex":false}}],"order":[{"column":1,"dir":"desc"}],"start":0,"length":10,"search":{"value":"","regex":false}}

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    Can you give me a link to the page please. There must be something else in the data returned from the server that is making jQuery's JSON parser fail on it.

    Allan

  • luernesluernes Posts: 4Questions: 1Answers: 1

    I cant, send you link because firewall. But posting data its the same I send you i my last comment. This solution work if I use get and delete columns, but datatables functionalities like sort and search doesn't work.

  • luernesluernes Posts: 4Questions: 1Answers: 1
    Answer ✓

    Hi Allan, and thanks for your answers and time, after much searching found the cause. Had nothing to do with Datatables, the problem was related to Cross - Site Request Forgery ( CSRF ). I had forgotten to send the header token in the post and the server was sending to me a wrong json response.

    regards

This discussion has been closed.