我可以使用以下代码成功对我的服务进行 AJAX 调用:
var serverData = { "ZoneParent": "123" };
var request = $.ajax({
type: "POST",
url: "/./Services/Reports.svc/getZones",
contentType: "application/json",
dataType: "json",
jsonp: null,
jsonpCallback: null,
data: JSON.stringify(serverData)
});
request.done(function (msg) {
alert(JSON.stringify(msg));
});
request.fail(function (jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
但是,当我尝试使用 Kendo 网格实现相同的调用时,我收到错误
The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'
对于 getZones。我的服务调用在 DataTables 上工作得很好,但我想切换到 Kendo。我已经搞乱了好几天了,但没有成功。该应用程序不是 MVC。这是我的 Kendo 代码片段:
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/./Services/Reports.svc/getZones",
dataType: "JSON",
data: { zoneParent: "123" },
type: "POST"
},
parameterMap: function (data, operation) {
return kendo.stringify(data);
}
},
schema: {
data: "d"
}
});
var grid = $("#allGrids").kendoGrid({
dataSource: dataSource,
height: 200
});
最佳答案
由于 cfeduke 提出了类似的建议,您可以尝试将 contentType 添加到传输读取配置的读取对象,就像您在 $.ajax 调用中所做的那样。
例如
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/./Services/Reports.svc/getZones",
dataType: "json",
contentType: "application/json",
data: { zoneParent: "123" },
type: "POST"
},
parameterMap: function (data, operation) {
return kendo.stringify(data);
}
},
关于asp.net - 如何让远程 JSON 与 ASP.NET 中的 Kendo 网格配合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14105372/