[WebInvoke(Method =
"GET"
)]
[WebGet]
public
string
HelloGET() {
return
"Hi THere from GET"
;
}
var
helloDS =
new
kendo.data.DataSource({
transport: {
read: {
// the remote service URL
type:
"GET"
,
url: oDataBasePath +
"/USDA.svc/HelloGET?$format=json"
,
dataType:
"jsonp"
,
contentType:
"application/json; charset=utf-8"
,
}
},
change:
function
() {
alert(
"Change"
);
},
error:
function
(){
alert(
"error"
);
}
});
helloDS.fetch();
So I see the GET works, I get my JSON back
{
"d"
: {
"Hello"
:
"Hi THere"
}
}
But Firebug throws the error:
This is the callback from Firebug
http:
//odata.gourmetsleuth.com/USDA.svc/HelloGET?$format=json&callback=jQuery17106241045930093632_1323571371269&_=1323573597895
So I'm getting my callback method
What am I doing wrong here? Shouldn't the odata method be returning that callback ID in the result?
10 Answers, 1 is accepted
type: "odata",
transport: {
read: oDataBasePath +
"/USDA.svc/HelloGET"
},
Then it formats the url as
http:
//odata.gourmetsleuth.com/USDA.svc/HelloGET?$format=json&$inlinecount=allpages&$callback=callback
However...that throws an error
callback({
"error"
: {
"code"
:
""
,
"message"
: {
"lang"
:
"en-US"
,
"value"
:
"Query options $expand, $filter, $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource."
}
}
})
...so I assume it needs to just be JSONP?
As you may know the remote transport of our DataSource is using jQuery ajax behind the scene. Thus calling odata service will require some additional settings:
However, note that dataSource expects an array to which to be bound, thus the service method you are using will not work as it is returning a string, which I suspect is the cause for the server error when default odata binding is used.
Rosen
the Telerik team
I originally got this:
"Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource."
But after adding the jsonp specific code from above I get:
"The query parameter '$format' begins with a system-reserved '$' character but is not recognized"
[JSONPSupportBehavior]
public
class
MarketTopologyService : DataService<USOPEntities>
{
public
static
void
InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule(
"TblZZZZ_Hierarchy"
, EntitySetRights.AllRead);
config.SetServiceOperationAccessRule(
"GetRegions"
, ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
[WebGet]
public
IQueryable<GetRegions_Result> GetRegions()
{
return
CurrentDataSource.GetRegions().AsQueryable<GetRegions_Result>();
}
}
$(
"#lstRegion"
).kendoDropDownList({
index: 0,
dataTextField:
"Region_Name"
,
dataValueField:
"Region_Name"
,
filter:
"contains"
,
dataSource: {
type:
"odata"
,
severFiltering:
true
,
serverPaging:
true
,
pageSize: 20,
transport: {
read: {
url:
"http://localhost/HtmlZZZZ/ZZZZZ/ZZZZZService.svc/GetRegions?$format=json&$callback=callback"
,
dataType:
'jsonp'
,
cache:
true
,
jsonp:
false
,
jsonpCallback:
'callback'
}
}
}
});
Jeff Moeller - AT&T
As the dataSource will set the $format not $callback internally, you should not append them to the URL manually. Therefore, please remove it from the URL and see if there is a change in the observed behavior.
All the best,Rosen
the Telerik team
read: {
url:
"http://localhost/HtmlTopology2/MarketTopology/MarketTopologyService.svc/GetRegions/?$callback=callback"
,
and still got:
"Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource."
Could you please provide a small sample which demonstrates the issue you are facing?
Regards,Rosen
the Telerik team
Thanks
Hello - i have similar issue:
I want to bind a pie chart to a json (aspx based) datasource.
here is the client side code i implemented:
var sharableDataSource = new kendo.data.DataSource({
transport:
{
read: {
type: "POST",
contentType: "application/json; charset=utf-8",
url: "HttpHandler.aspx/Top5Defects",
dataType: "json"
}
},
error: function (e) {
alert(e);
}
});
function createChart() {
$("#chart").kendoChart({
theme: $(document).data("kendoSkin") || "default",
title: {
text: "Top 5 Defects"
},
legend: {
position: "bottom"
},
seriesDefaults: {
labels: {
visible: true,
format: "{0}"
}
},
tooltip: {
visible: true,
format: "{0}%"
},
dataSource: sharableDataSource,
series: [{
type: "pie",
field: "DefectCount" ,
categoryField: "Defect"
}]
});
}
$(document).ready(function () {
setTimeout(function () {
createChart();
}, 400);
});
Here is what returned from my aspx web method (aspx encapsulates json data in the d property):
{"d":[{"Defect":"65-Missing solder - printer\\sten","DefectCount":"3983"},
{"Defect":"16-Pin in air / Tombston","DefectCount":"1871"},
{"Defect":"41-Shift component","DefectCount":"1598"},
{"Defect":"9-NFF-no failure found","DefectCount":"1489"},
{"Defect":"82-Missing solder","DefectCount":"1462"}]}
For some reason, the Pie chart is not being displayed and i get no error.
If i change the datasource to a local datasource:
var seriesData = [{ Defect: "def1", DefectCount: 200 }, { Defect: "def2", DefectCount: 200}];
Then the pie is displayed.
I'm pretty sure it's an issue with my returned json response.
Please advice
I believe the problem is caused by the fact that you did not specified the root element that contains the data array.
var
sharableDataSource =
new
kendo.data.DataSource({
transport: {
read: {
type:
"POST"
,
contentType:
"application/json; charset=utf-8"
,
url:
"HttpHandler.aspx/Top5Defects"
,
dataType:
"json"
}
},
schema: {
data:
"d"
//the services return JSON in the following format { "d": <result> }. Specify how to get the result.
}
});
Kind regards,
Alexander Valchev
the Telerik team
var sharableDataSource = new kendo.data.DataSource({
transport:
{
read: {
type: "POST",
contentType: "application/json; charset=utf-8",
url: "HttpHandler.aspx/Top5Defects",
dataType: "json"
}
},
error: function (e) {
alert(e);
},
schema: {
data: 'd'
},
columns: [
{
field: "Defect"
},
{
field: "DefectCount"
}
]
});