there is a dropdown in my page .i am trying to fetch details using datatable.min js based on the id of the dropdown in asp.net mvc..i am getting this error .plz help..here is my js
<script type="text/javascript">
$(document).ready(function () {
$('#ddlTitle').change(function () {
if ($("[id$='ddlTitle']").val() == 0) {
$("[id$='ddlTitle']").focus();
alert("Please select");
$('#CustomerDetails').html(" ");
return false;
}
$('#container').html("<img src='images/loading.gif' alt='Loading!'>");
getData();
// $.ajax({
// type: "POST",
// contentType: "application/json; charset=utf-8",
// data: "{ CustomerID: '" + $('#ddlTitle').val() + "'}",
// url: "TestJqueryShowData.aspx/FetchCustomer",
// dataType: "json",
// success: function (data) {
// $('#CustomerDetails').html(" ");
// var Company = data.d;
// $('#CustomerDetails').append
// ('<p><strong>' + Company.CompanyName + "</strong><br />" +
// Company.Address + "<br />" +
// Company.City + "<br />" +
// Company.Region + "<br />" +
// Company.PostalCode + "<br />" +
// Company.Country + "<br />" +
// Company.Phone + "<br />" +
// Company.Fax + "</p>")
// }
// });
});
});
function getData() {
$("#container").css('display', 'block');
var oTable = $('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "Home/AjaxHandler?id=" + $('#ddlTitle').val(),
"bProcessing": true,
"aoColumns": [
{ "sName": "ID",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href=\"Company/Details/' + oObj.aData[0] + '\">View</a>';
}
},
{ "sName": "COMPANY_NAME" },
{ "sName": "ADDRESS" },
{ "sName": "TOWN" }
]
});
}
</script>
here is my view page
<link href="@Url.Content("~/Content/dataTables/demo_table.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/DataTableGridJs/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/DataTableGridJs/Scripts/jquery.dataTables.min.js")" type="text/javascript"></script>
<body>
Dynamic DDL: @Html.DropDownList("ddlTitle", new SelectList((System.Collections.IEnumerable)ViewData["empList"], "employeeId", "employeeName"), new { @class = "ddlCSS" })
<div id="container" style="display: none">
<div id="demo">
<table id="myDataTable" class="display">
<thead>
<tr>
<th>
ID
</th>
<th>
Company name
</th>
<th>
Address
</th>
<th>
Town
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function () {
$('#ddlTitle').change(function () {
if ($("[id$='ddlTitle']").val() == 0) {
$("[id$='ddlTitle']").focus();
alert("Please select");
$('#CustomerDetails').html(" ");
return false;
}
$('#container').html("<img src='images/loading.gif' alt='Loading!'>");
getData();
// $.ajax({
// type: "POST",
// contentType: "application/json; charset=utf-8",
// data: "{ CustomerID: '" + $('#ddlTitle').val() + "'}",
// url: "TestJqueryShowData.aspx/FetchCustomer",
// dataType: "json",
// success: function (data) {
// $('#CustomerDetails').html(" ");
// var Company = data.d;
// $('#CustomerDetails').append
// ('<p><strong>' + Company.CompanyName + "</strong><br />" +
// Company.Address + "<br />" +
// Company.City + "<br />" +
// Company.Region + "<br />" +
// Company.PostalCode + "<br />" +
// Company.Country + "<br />" +
// Company.Phone + "<br />" +
// Company.Fax + "</p>")
// }
// });
});
});
function getData() {
$("#container").css('display', 'block');
var oTable = $('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "Home/AjaxHandler?id=" + $('#ddlTitle').val(),
"bProcessing": true,
"aoColumns": [
{ "sName": "ID",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href=\"Company/Details/' + oObj.aData[0] + '\">View</a>';
}
},
{ "sName": "COMPANY_NAME" },
{ "sName": "ADDRESS" },
{ "sName": "TOWN" }
]
});
}
</script>
here is my view page
<link href="@Url.Content("~/Content/dataTables/demo_table.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/DataTableGridJs/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/DataTableGridJs/Scripts/jquery.dataTables.min.js")" type="text/javascript"></script>
<body>
Dynamic DDL: @Html.DropDownList("ddlTitle", new SelectList((System.Collections.IEnumerable)ViewData["empList"], "employeeId", "employeeName"), new { @class = "ddlCSS" })
<div id="container" style="display: none">
<div id="demo">
<table id="myDataTable" class="display">
<thead>
<tr>
<th>
ID
</th>
<th>
Company name
</th>
<th>
Address
</th>
<th>
Town
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>