我有一个返回以下json的OData服务。
{
"@odata.context":"http://testing.test.com/DataService/Data","value":[
{"ID":1,"Description":"Test 1"}
,{"ID":2,"Description":"Test 2"}
,{"ID":3,"Description":"Test 3"}]
}
如果odata服务和调用odata服务的网页都在localhost上,那么一切正常
如果odata服务在testing.test.com这样的主机上,并且调用odata服务的网页在localhost上,那么一切都不能正常工作。
我可以在fiddler中看到数据在localhost上返回到客户端,但网格从不显示数据。
<script>
$(document).ready(function () {
var crudServiceBaseUrl = "http://localhost/DataService/Data",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl,
dataType: "json"
},
schema: {
data: "value",
model: {
id: "ID"
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
columns: [
{ field: "ID", title: "ID", width: 70 }]
});
});
</script>
odata是通过ASP.NET web api odata而非wcf托管的。
Web客户端通过ASP.NET Web应用程序通用html托管。
我读到某个地方我可能要设置crossDomainScriptAccessEnabled =&#34; true&#34;在web.config但似乎只适用于WCF webHttpBinding。但我使用的是WEB API而不是WCF。
答案 0 :(得分:0)
终于开始工作了。
必须修改ASP.NET Web API Odata服务以启用CORS(跨源请求)。
http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
http://blogs.telerik.com/kendoui/posts/11-08-24/cross-domain_queries_to_odata_services_with_jquery