Only after the page elements load, you can call anything working on those elements (including #example)
var url = 'http://localhost:8080/signalr';
var connection = $.hubConnection(url);
var hubProxy = connection.createHubProxy('HubClass');
$(document).ready(function () {
hubProxy.on('DeviceDataResults', processDeviceDataResults);
connection.start().done(function () {
$("#GetDeviceData").click(function() {
hubProxy.invoke('GetDeviceData');
});
});
});
function processDeviceDataResults(results) {
$('#example').dataTable({
"aaData": results
});
If this helps please take time and accept the solution so others may find it. Thank you.