I've got a page that uses as WCF web service to do some back-end processing. I can do it quite happily using a standard AJAX call. But I would like to do a similar thing using a Kendo DataSource. The test web service I'm calling simply takes a single argument called "param" and returns it back as:
Here is the standard ajax call. Both the success and error functions display things for me properly. The data comes back as json data, with a single value called "TestCallParamResult". I can see this using fiddler as well as follows.
{"TestCallParamResult":"you passed: HI"}
Here is my attempt at doing it using a datasource. I can see the data coming back in fiddler, but I'm probably wrong in the way I've defined the schema or am trying to access the result. I would like to see the alert actually display the contents of the returned string. I should add that Javascript & jquery are not my first language!
One other thing on this - the service is called with or without the ds.read() call, is that normal?
Thanks,
Tom
public string TestCallParam(string param){ return "you passed: " + param;}Here is the standard ajax call. Both the success and error functions display things for me properly. The data comes back as json data, with a single value called "TestCallParamResult". I can see this using fiddler as well as follows.
{"TestCallParamResult":"you passed: HI"}
$(document).ready(function () { $("#TextBox1").text("Starting"); var args = new Object(); args.param = "HI"; $.ajax({ type: "POST", url: "cccjq.svc/TestCallParam", contentType: "application/json; charset=utf-8", data: JSON.stringify(args), dataType: "json", processdata: false, success: function (msg) { alert(msg.TestCallParamResult); }, error: ServiceFailed });})function ServiceFailed(result) { alert('Service call failed.\r\nStatus = ' + result.status + '.\r\n' + result.statusText);}Here is my attempt at doing it using a datasource. I can see the data coming back in fiddler, but I'm probably wrong in the way I've defined the schema or am trying to access the result. I would like to see the alert actually display the contents of the returned string. I should add that Javascript & jquery are not my first language!
$(document).ready(function () { $("#TextBox1").text("Starting"); var args = new Object(); args.param = "HI"; var ds = new kendo.data.DataSource({ transport: { read: { type: "POST", url: "cccjq.svc/TestCallParam", contentType: "application/json; charset=utf-8", dataType: 'json' }, parameterMap: function (options, operation) { return JSON.stringify(args); } }, schema: { data: "TestCallParamResult", type: 'json' }, change: function (e) { alert(x); }, error: function (e) {
// dont know if this is right either
alert('Service call failed.\r\nStatus = ' + e.status + '.\r\n' + e.statusText); } }); ds.read();One other thing on this - the service is called with or without the ds.read() call, is that normal?
Thanks,
Tom