jquery datatables Ajax-Error / http://datatables.net/tn/7
Asked Answered
D

5

15

Please look at my problem below:

I use in my MVC-Web-Applikation the jquery datatables. When i display only 8 columns, everything works fine. But with 1 more column, i get the ajax-error-message, see title.

The controller wokrs fine, because the 8 columns work fine. Here my code of the view:

<script type="text/javascript">
    $(document).ready(function () {
        var table = $('#example').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": "@Url.Action("List", "DFS_Akustik")",
            "columns": [
                { "data": "ID" },
                { "data": "MessID" },
                { "data": "KL_ID" },
                { "data": "MP_ID" },
                { "data": "LwLin50ss" },
                { "data": "LwLin63ss" },
                { "data": "LwLin80ss" },
                { "data": "LwLin100ss" },
                //{ "data": "LwLin125ss" },
            ],
        });
    });
</script>

You can the, that the last columns is not active, then:

http://ziehl-abegg.com/files/work.jpg

When i delte the // of the last column, then:

http://ziehl-abegg.com/files/work_not.jpg

How can i solve this problem?? Please help me... I look for a solution, since Monday, the whole day!!

Thank you.

Greetz Vegeta_77

Dogeatdog answered 4/3, 2015 at 14:51 Comment(4)
What error did your server return? The error message in your second picture literally tells you how to figure out what's wrong.Wavawave
Also, can you find out for me what "ajax": "@Url.Action("List", "DFS_Akustik")" is rendered as in the browser?Wavawave
show the HTML please.Escuage
There's obviously something about that last column that datatables doesn't like. Is the name correct? Can you see the json response in Firebug?Assignation
D
10

I have it, my friends!!!!!!!!!!!!!!!!!!!!!!! Very NICE :-)

Here is the Solution:

$(document).ready(function() {
    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "scripts/post.php",
            "type": "POST"
        },
        "columns": [
            { "data": "first_name" },
            { "data": "last_name" },
            { "data": "position" },
            { "data": "office" },
            { "data": "start_date" },
            { "data": "salary" }
        ]
    } );
} );

I had just to edit the "ajax". When you use the "type" "POST", then it works.

Thank you very much.

Greetz Vegeta_77

Dogeatdog answered 5/3, 2015 at 7:58 Comment(2)
Had exactly the same problem. Any idea why this fixes the issue?Rebel
We've hit this problem, too. As far as I can tell, it's because the generated callback exceeds the 2048 character limit for GET requests. This is not a hard limit per the standard, but many web servers enforce it.Keto
D
0

Good morning. Here the HTML / table header:

<div style="width: auto; height: 750px; overflow-x: auto; overflow-y: auto;">
    <table id="example" class="table display" cellspacing="0">
        <thead>
            <tr>
                <th>ID</th>
                <th>MessID</th>
                <th>KL_ID</th>
                <th>MP_ID</th>
                <th>LwLin50ss</th>
                <th>LwLin63ss</th>
                <th>LwLin80ss</th>
                <th>LwLin100ss</th>
                @*<th>LwLin125ss</th>*@
            </tr>
        </thead>
    </table>
</div>

The server side result is good, look:

http://ziehl-abegg.com/files/ServerSide.jpg

@Sippy. I don't understand our second question.

The names are all correct, look at the third picture/link. Here is the methode "List" from the controller:

public JsonResult List([ModelBinder(typeof(DataTablesBinder))] 
IDataTablesRequest requestModel)
{
List<View_DFS_Akustik> myOriginalDataSet = dbman.View_DFS_Akustik.ToList();
List<View_DFS_Akustik> myFilteredData = dbman.Set<View_DFS_Akustik>().FullTextSearch(requestModel.Search.Value).ToList();

//Apply filter to your dataset based only on the columns that actually have a search value.
foreach (var column in requestModel.Columns.GetFilteredColumns())
{
    string query = column.Data + ".Contains(\"" + column.Search.Value + "\")";
    myFilteredData = myFilteredData.Where(query).ToList();
}

//Set your dataset on the same order as requested from client-side either directly on your SQL code or easily
//into any type or enumeration.
bool isSorted = false;
foreach (var column in requestModel.Columns.GetSortedColumns())
{
    if (!isSorted)
    {
        // Apply first sort.
        if (column.SortDirection == Column.OrderDirection.Ascendant)
            myFilteredData = myFilteredData.OrderBy(column.Data).ToList();
        else
            myFilteredData = myFilteredData.OrderBy(column.Data + " descending").ToList();

        isSorted = true;
    }
    else
    {
        if (column.SortDirection == Column.OrderDirection.Ascendant)
            myFilteredData = myFilteredData.OrderBy(column.Data).ToList();
        else
            myFilteredData = myFilteredData.OrderBy(column.Data + " descending").ToList();
    }
}

var paged = myFilteredData.Skip(requestModel.Start).Take(requestModel.Length);
return Json(new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count()), JsonRequestBehavior.AllowGet);
}

THX. Vegeta_77

Dogeatdog answered 5/3, 2015 at 7:43 Comment(0)
C
0
I was getting the error : DataTables warning: table id=myTable - Ajax error. For more information about this error, please see http://datatables.net/tn/7  like this i checked my complete code twisly then i finally

This is my code :
var dtable;
$(document).ready(function () {
    var dtable = $('#myTable').DataTable(
        {
            "ajax": {
                "url":"~/Admin/Product/AllProducts"
            },
            "columns": [
                { "data": "name" },
                { "data": 'description' },
                { "data": "price" }                         
            ]
        });
});  for retrive data through ajax it renders data 

i changed
        "ajax": {
            "url": "../Admin/Product/AllProducts"
        }
try this code in your url : "../"  
Crust answered 29/6, 2023 at 9:11 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Ava
R
0

My problem was in the php version. When changing the version from 8.0 to 7.4, everything worked.

Renie answered 27/10, 2023 at 10:41 Comment(1)
Rolling back PHP is a less than ideal solution, and especially as new versions of PHP are released. Did the code-based answers previously proposed not work for you? They seem like a better approach if they do.Partible
M
0

My project Laravel + Datatables.

This issue has shown for me on production but not on local, I solve this changing the routes to Datatables on this files:

File: config/app.php the line:

'DataTables' => Yajra\DataTables\Facades\DataTables::class,

change for this line:

'DataTables' => Yajra\DataTables\DataTables::class,

on my controllers change this line:

use Yajra\DataTables\Facades\Datatables;

for:

use Yajra\DataTables\Datatables;

It works for me, hope somebody find useful this information, thanks.

Matriarchate answered 2/2 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.