[英]jQuery DataTables requested unknown parameter
I've having a hard time figuring out why this doesn't work... So the jsfiddle will work. 我很难弄清楚为什么它不起作用...所以jsfiddle将起作用。
Now the jsfiddle works because I have created a var exactly to what console.log(data)
in the code below produces. 现在,jsfiddle可以正常工作了,因为我创建了一个与以下代码中的console.log(data)
完全相同的变量。
$(document).ready(function () {
$("#<%= ddlProduct.ClientID %>").change(function (e) {
var P_ID = $("#<%= ddlProduct.ClientID %>").val();
$.ajax({
headers: {
Accept: "*/*"
},
type: "POST",
url: "../service/product.asmx/GetProduct",
data: '{"jsondata" : {"P_ID" : "' + P_ID + '"}}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg, status, metaData) {
var data = msg.d.P_ID;
buildMyDatatable(data);
},
error: function (ex, status) {
//alert(ex.responseText);
alert("error");
}
});
});
function buildMyDatatable(data) {
console.log(data);
$("#table_id").dataTable().fnDestroy();
$('#table_id').dataTable({
"bProcessing": true,
"aoColumns": [
{ mData: "Q_ID"},
{ mData: "Business" },
{ mData: "Product" },
{ mData: "QuestionType" },
{ mData: "Question" },
{ mData: "Answer" },
{ mData: "AskBy" },
{ mData: "AnsBy" },
{ mData: "AnsByEmail" },
{ mData: "DateAsk" },
{ mData: "DateAns" }
],
"aaData": data,
});
}
});
My question is, why does var data = server.hardcoded.response
work vs it not working when using the actual ajax response? 我的问题是,为什么使用实际的ajax响应时, var data = server.hardcoded.response
起作用而相对于它不起作用?
When using the ajax response I get this error. 使用ajax响应时,出现此错误。
DataTables warning (table id = 'table_id'): Requested unknown parameter 'Q_ID' from the data source for row 0
I have solved the problem. 我已经解决了问题。
var data = $.parseJSON(data);
inherently JavaScript was passing it as a string and not an object. 本质上,JavaScript将其作为字符串而不是对象传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.