jquery datatable ajax返回一个错误
下面是我的代码,它在VisualStudio12的机器中完美地从web服务返回症状列表jquery datatable ajax返回一个错误,jquery,ajax,datatables,Jquery,Ajax,Datatables,下面是我的代码,它在VisualStudio12的机器中完美地从web服务返回症状列表 $('#manLeg').mapster($.extend({}, options,{ onClick: function (e) { if (e.key === 'toes') { $.ajax({ url: "SympsService.asmx/GetSymptoms", m
$('#manLeg').mapster($.extend({}, options,{
onClick: function (e) {
if (e.key === 'toes')
{
$.ajax({
url: "SympsService.asmx/GetSymptoms",
method: "post",
dataType: "json",
data: JSON.stringify({ organ_name: "toes" }),
contentType: "application/json",
success: function (data) {
createDataTable('#choiseTable', null);
createDataTable("#symptomsTable", null);
$('#choiseTable').on("click", "tbody button", function (evt) { moveRow(evt, '#choiseTable', '#symptomsTable'); } )
$('#symptomsTable').on("click", "tbody button", function (evt) { moveRow(evt, '#symptomsTable', '#choiseTable'); })
var sympList = 'GetSymptoms' ? JSON.parse(data.d) : data.d;
createDataTable('#symptomsTable', sympList);
function createDataTable(target, data) {
$(target).DataTable({
destroy: true,
paging: false, searching: false, info: false, data: data,
columnDefs: [{
targets: [-1], render: function () {
return "<button type='button'>" + (target == '#choiseTable' ? 'Remove' : 'Choose') + "</button>"
}
}],
columns: [
{
'data': 'Sympt',
'title': 'toes Symptoms',
class: 'center'
},
{
'data': null, 'title': 'Action'
}
]
});
}
function moveRow(evt, fromTable, toTable) {
var table1 = $(fromTable).DataTable();
var table2 = $(toTable).DataTable();
var tr = $(evt.target).closest("tr");
var row = table1.rows(tr);
var obj = { 'Sympt': row.data()[0].Sympt };
table2.row.add(obj).draw();
row.remove().draw();
}
},
error: function (error, status) {
console.log(error);
debugger;
}
});
这让我发疯,因为我需要在那台机器上运行它,但无法理解这个错误的含义。
任何形式的帮助都将不胜感激。提前感谢。我重新组织了一下,并提出了这个
$('#manLeg').mapster($.extend({}, options,
{
onClick: function (e) {
if (e.key === 'toes') {
doAjax();
}
}
}));
function doAjax() {
$.ajax({
url: "SympsService.asmx/GetSymptoms",
method: "post",
dataType: "json",
data: JSON.stringify({ organ_name: "toes" }),
contentType: "application/json",
success: function (data) {
createDataTable('#choiseTable', null);
createDataTable("#symptomsTable", null);
$('#choiseTable').on("click", "tbody button", function (evt) { moveRow(evt, '#choiseTable', '#symptomsTable'); } )
$('#symptomsTable').on("click", "tbody button", function (evt) { moveRow(evt, '#symptomsTable', '#choiseTable'); })
var sympList = 'GetSymptoms' ? JSON.parse(data.d) : data.d;
createDataTable('#symptomsTable', sympList);
},
error: function (responseError, status) {
console.log(responseError);
debugger;
}
});
}
function createDataTable(target, data) {
$(target).DataTable({
destroy: true,
paging: false, searching: false, info: false, data: data,
columnDefs: [{
targets: [-1], render: function () {
return "<button type='button'>" + (target == '#choiseTable' ? 'Remove' : 'Choose') + "</button>"
}
}],
columns: [
{
'data': 'Sympt',
'title': 'toes Symptoms',
class: 'center'
},
{
'data': null, 'title': 'Action'
}
]
});
}
function moveRow(evt, fromTable, toTable) {
var table1 = $(fromTable).DataTable();
var table2 = $(toTable).DataTable();
var tr = $(evt.target).closest("tr");
var row = table1.rows(tr);
var obj = { 'Sympt': row.data()[0].Sympt };
table2.row.add(obj).draw();
row.remove().draw();
}
$('#manLeg').mapster($.extend({},选项,
{
onClick:函数(e){
如果(e.key=='toes'){
doAjax();
}
}
}));
函数doAjax(){
$.ajax({
url:“SympsService.asmx/GetSymptoms”,
方法:“张贴”,
数据类型:“json”,
数据:JSON.stringify({organ_name:“toes”}),
contentType:“应用程序/json”,
成功:功能(数据){
createDataTable('#ChoiceTable',null);
createDataTable(“症状稳定”,null);
$(“#choiseTable”)。在(“单击”,“tbody按钮”,函数(evt){moveRow(evt),#choiseTable',“#症状稳定”);}
$(“#症状稳定”)。在(“单击”、“tbody按钮”、函数(evt){moveRow(evt)、#症状稳定”、“可选择”);}
var sympList='GetSymptoms'?JSON.parse(data.d):data.d;
createDataTable(“#症状稳定”,症状列表);
},
错误:功能(响应错误、状态){
console.log(responseError);
调试器;
}
});
}
函数createDataTable(目标,数据){
$(目标).DataTable({
摧毁:没错,
分页:false,搜索:false,信息:false,数据:data,
columnDefs:[{
目标:[-1],呈现:函数(){
返回“+(目标==”#可选择“?”删除“:”选择“+”
}
}],
栏目:[
{
'数据':'Sympt',
“标题”:“脚趾症状”,
班级:'中心'
},
{
“数据”:null,“标题”:“操作”
}
]
});
}
函数moveRow(evt、fromTable、toTable){
var table1=$(fromTable).DataTable();
var table2=$(toTable).DataTable();
var tr=$(evt.target);
var行=表1.行(tr);
var obj={'Sympt':row.data()[0].Sympt};
表2.row.add(obj.draw();
row.remove().draw();
}
错误处理程序有三个参数。请全部使用。此行var sympList='GetSymps'?parse(data.d):data.d;对我来说毫无意义。如果您的web服务返回一个字符串,则需要执行JSON.parse。如果它返回and对象,它可能已经被序列化了。在任何情况下,它的行为都是一致的。如果在visual studio中停止调试器行,则应该能够检查错误对象。检查error.responseText或error.response.JSON.message中的值以获取实际错误。正如安全检查一样,将error:function(error,status)更改为error:function(reqError,status)或除“error”以外的任何内容看看它在控制台中的显示是否相同。为什么在ajax调用中定义了您的函数?很抱歉我最近的评论。非常感谢您的帮助。我在另一台机器上试用了它,它运行得非常好……这可能就是visual studio安装的问题。谢谢
$('#manLeg').mapster($.extend({}, options,
{
onClick: function (e) {
if (e.key === 'toes') {
doAjax();
}
}
}));
function doAjax() {
$.ajax({
url: "SympsService.asmx/GetSymptoms",
method: "post",
dataType: "json",
data: JSON.stringify({ organ_name: "toes" }),
contentType: "application/json",
success: function (data) {
createDataTable('#choiseTable', null);
createDataTable("#symptomsTable", null);
$('#choiseTable').on("click", "tbody button", function (evt) { moveRow(evt, '#choiseTable', '#symptomsTable'); } )
$('#symptomsTable').on("click", "tbody button", function (evt) { moveRow(evt, '#symptomsTable', '#choiseTable'); })
var sympList = 'GetSymptoms' ? JSON.parse(data.d) : data.d;
createDataTable('#symptomsTable', sympList);
},
error: function (responseError, status) {
console.log(responseError);
debugger;
}
});
}
function createDataTable(target, data) {
$(target).DataTable({
destroy: true,
paging: false, searching: false, info: false, data: data,
columnDefs: [{
targets: [-1], render: function () {
return "<button type='button'>" + (target == '#choiseTable' ? 'Remove' : 'Choose') + "</button>"
}
}],
columns: [
{
'data': 'Sympt',
'title': 'toes Symptoms',
class: 'center'
},
{
'data': null, 'title': 'Action'
}
]
});
}
function moveRow(evt, fromTable, toTable) {
var table1 = $(fromTable).DataTable();
var table2 = $(toTable).DataTable();
var tr = $(evt.target).closest("tr");
var row = table1.rows(tr);
var obj = { 'Sympt': row.data()[0].Sympt };
table2.row.add(obj).draw();
row.remove().draw();
}