Hi,
I know this question has been posted many times over the internet, but I'm unable to find something specific to get my query fixed mainly due either i'm not understanding something due to little knowledge or that's not the case for me. I'm new to ASP.NET and AJAX, and following some tutorials here.
I'm getting error as below and further below posting a code. I've matched the code from tutorial. Initially it worked but now it's not working, and my exercise doesn't work created on similar pattern.
Could someone help me out, what is happening here please?
Thanks.
jquery.datatables.js:3406 Uncaught TypeError: Cannot read property 'length' of undefined
at jquery.datatables.js:3406
at callback (jquery.datatables.js:2528)
at Object.success (jquery.datatables.js:2558)
at fire (jquery-1.10.2.js:3062)
at Object.fireWith [as resolveWith] (jquery-1.10.2.js:3174)
at done (jquery-1.10.2.js:8249)
at XMLHttpRequest.callback (jquery-1.10.2.js:8792)
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}<h2>Customers</h2><table id="customers" class="table table-bordered table-hover"><thead><tr><th>Customer</th><th>Membership Type</th><th>Delete</th></tr></thead><tbody></tbody></table>
@section scripts
{
<script>$(document).ready(function () {
var table = $("#customers").DataTable({
ajax: {
url: "/api/customers",
datasrc: ""
},
columns: [
{
data: "name",
render: function (data, type, customer) {
return "<a href='/customers/edit/" + customer.Id + "'>" + customer.name + "</a>";
}
},
{
data: "membershipType.name"
},
{
data: "id",
render: function (data) {
return "<button class='btn-link js-delete' data-customer-id=" + data + ">Delete</button>";
}
}
]
});$("#customers").on("click", ".js-delete", function () {
var button = $(this);
bootbox.confirm("Are you sure you want to delete this customer?", function (result) {
if (result)$.ajax({
url: "/api/customers/" + button.attr("data-customer-id"),
method: "DELETE",
success: function () {
table.row(button.parents("tr")).remove().draw();
}
});
});
});
});</script>
}