Is there a way to make an ajax call in Kendo without involving the grid? I am new to Kendo and struggling to populate a span element with data fetched from one of my controller methods. The data is present as I can see it in the alert message, but it's not displaying in my view.
var viewModel = kendo.observable({
Text: "SomeText"
});
$.ajax({
url: "/Home/GetPerson",
dataType: "json",
type: "POST",
success: function (data) {
$.extend(viewModel, data);
alert(data.Name); //displays correctly.
}
})
kendo.bind(document.body, viewModel);
This is how I have set up my view:
<span data-bind="text: Name"></span>
I managed to get it working by making some modifications, but it feels inelegant. Is there a cleaner approach to achieve the same result?
var viewModel = kendo.observable({
AjaxData: null
});
$.ajax({
url: "/Home/GetPerson",
dataType: "json",
type: "POST",
success: function (data) {
viewModel.set("AjaxData", data);
alert(data.Name); //displays correctly.
}
})
kendo.bind(document.body, viewModel);
Updated View:
<span data-bind="text: AjaxData.Name"></span>