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

☆樱花仙子☆ 提交于 2019-12-03 06:15:06

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

Vegeta_77

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!