Javascript 我的jquery datatable ajax调用未到达服务器,而是显示JSON格式无效警报
我有一个简单的网页,其中包含一个表。我需要使用ajax调用服务器端方法来填充表。我使用了jquerydatatable。jquery的代码是Javascript 我的jquery datatable ajax调用未到达服务器,而是显示JSON格式无效警报,javascript,jquery,json,ajax,datatable,Javascript,Jquery,Json,Ajax,Datatable,我有一个简单的网页,其中包含一个表。我需要使用ajax调用服务器端方法来填充表。我使用了jquerydatatable。jquery的代码是 $(document).ready(function() { $("#tableUserList").DataTable({ "processing": true, "dataSource": "", "serverSide": true, "ajax": "AdminHome.aspx/getUsersForTable
$(document).ready(function() {
$("#tableUserList").DataTable({
"processing": true,
"dataSource": "",
"serverSide": true,
"ajax": "AdminHome.aspx/getUsersForTable"
});
});
我的HTML表格是
<table id="tableUserList" class="table table-hover">
<thead>
<tr>
<th>UserID</th>
<th>Username</th>
<th>UserType</th>
<th>FirstName</th>
<th>LastName</th>
<th>Address</th>
<th>Email</th>
<th>Contact</th>
</tr>
</thead>
<tbody></tbody>
</table>
控件未到达服务器,而是显示一条警报消息,消息为:DataTables警告:table id=tableUserList-JSON响应无效。有关此错误的详细信息,请参阅
我检查了邮件中给出的url,但没有找到任何解决方案。
我做错了什么。假设您已正确加载CDN或所需插件,并且getUsersForTable返回数据,下面是代码
<script>
$(document).ready(function () {
$.ajax({
url: 'AdminHome.aspx/getUsersForTable',
method: 'post',
dataType: 'json',
success: function (data) {
$('#tableUserList').dataTable({
paging: true,
sort: true,
searching: true,
scrollY: 200,
data: data,
columns: [
{ 'data': 'UserID' },
//rest follows with column names].
//end of datatable
});
//end of success function
}
//end of ajax call
});
//end of ready event.
});
$(文档).ready(函数(){
$.ajax({
url:'AdminHome.aspx/getUsersForTable',
方法:“post”,
数据类型:“json”,
成功:功能(数据){
$('#tableUserList')。数据表({
是的,
排序:对,
搜索:是的,
卷轴:200,
数据:数据,
栏目:[
{'data':'UserID'},
//rest后面跟着列名]。
//数据表末尾
});
//成功结束函数
}
//ajax调用结束
});
//准备就绪事件结束。
});
脚本中的ajax调用在哪里,只有datatable返回数据,它可能不是有效的JSON,仍然显示相同的消息。这个解决方案对我不起作用。很抱歉
<script>
$(document).ready(function () {
$.ajax({
url: 'AdminHome.aspx/getUsersForTable',
method: 'post',
dataType: 'json',
success: function (data) {
$('#tableUserList').dataTable({
paging: true,
sort: true,
searching: true,
scrollY: 200,
data: data,
columns: [
{ 'data': 'UserID' },
//rest follows with column names].
//end of datatable
});
//end of success function
}
//end of ajax call
});
//end of ready event.
});