Can't retrieve data from OData
Can't retrieve data from OData
I have an OData source generated by a C# program returning the following:
{
"odata.metadata":"http://appdev36/SmrDataService/$metadata#Statuses","value":[
{
"StatusId":1,"DisplayLabel":"New","DisplayColour":0,"SortOrder":1
},{
"StatusId":2,"DisplayLabel":"Assigned","DisplayColour":0,"SortOrder":3
},{
"StatusId":3,"DisplayLabel":"Processed","DisplayColour":0,"SortOrder":2
},{
"StatusId":4,"DisplayLabel":"Review","DisplayColour":0,"SortOrder":4
},{
"StatusId":5,"DisplayLabel":"Authorised","DisplayColour":0,"SortOrder":5
}
]
}
And my script is the following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>DataTable Test</title>
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/DataTables-1.9.4/media/css/demo_page.css" rel="stylesheet" />
<link href="Content/DataTables-1.9.4/media/css/demo_table.css" rel="stylesheet" />
<script src="Scripts/DataTables-1.9.4/media/js/jquery.js"></script>
<script src="Scripts/DataTables-1.9.4/media/js/jquery.dataTables.min.js"></script>
<script src="Scripts/DataTables-1.9.4/media/js/jquery.dataTables.odata.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#ResultGrid').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://appdev36/SmrDataService/Statuses",
"aoColumns": [
{ "mData": "StatusId" },
{ "mData": "DisplayLabel" },
{ "mData": "DisplayColour" },
{ "mData": "SortOrder" }
],
"fnServerData": fnServerOData,
"iODataVersion": 4,
"bUseODataViaJSONP": true
});
});
</script>
</head>
<body>
<h1>DataTables Test</h1>
<br />
<br />
<table class="display" id="ResultGrid" style="border-collapse: unset; border: 1px solid; padding: 5px;">
</table>
</body>
</html>
With all the above I can't get any results, instead of a positive answer from my page, I'm getting the following error on Chrome:
Uncaught SyntaxError: Unexpected token :
On Internet Explorer 11 - I get a similar error message, basically pointing to the same:
SCRIPT1004: Expected ';'
File: Statuses, Line: 2, Column: 19
From what I could understand, the error is on my OData response, in both browsers I'm getting an indication to look for something wrong on line 2 column 19 and this is the symbol ':' right after "odata.metadata".
I'm not sure what could be the cause of issue, I'm fairly new to OData but the error message seems very consistent. Any help is welcomed, thanks in advance!