What am I doing wrong?
What am I doing wrong?
I'm trying to load the data into the datatable from a webservice that returns the data in JSON format. I keep getting errors here:
oTable.fnAddData(["" + data.ListExercise[i].exercise_id, data.ListExercise[i].exercise_value]);
or oTable is undefined.
What am I doing wrong?
Here is my code:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="MyFitnessApp._Default" %>
Exercise ID
Exercise Value
Below is my dataTable.js file:
function loadData() {
$.ajax({
url: "../webService/exercise_ws.asmx/ExerciseGet",
data: "{}",
success: function (data) {
for (var i = 0; i < data.ListExercise.length; i++) {
alert(i);
var eVal = data.ListExercise[i];
$('#example').dataTable.fnAddData(["" + data.ListExercise[i].exercise_id, data.ListExercise[i].exercise_value]);
}
}
});
}
$(document).ready(function () {
$.ajaxSetup({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{}",
dataFilter: function (data) {
var msg;
if (typeof (JSON) !== 'undefined' &&
typeof (JSON.parse) === 'function')
msg = JSON.parse(data);
else
msg = eval('(' + data + ')');
if (msg.hasOwnProperty('d')) {
return msg.d;
} else {
return msg;
}
}
});
loadData();
});
oTable.fnAddData(["" + data.ListExercise[i].exercise_id, data.ListExercise[i].exercise_value]);
or oTable is undefined.
What am I doing wrong?
Here is my code:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="MyFitnessApp._Default" %>
Exercise ID
Exercise Value
Below is my dataTable.js file:
function loadData() {
$.ajax({
url: "../webService/exercise_ws.asmx/ExerciseGet",
data: "{}",
success: function (data) {
for (var i = 0; i < data.ListExercise.length; i++) {
alert(i);
var eVal = data.ListExercise[i];
$('#example').dataTable.fnAddData(["" + data.ListExercise[i].exercise_id, data.ListExercise[i].exercise_value]);
}
}
});
}
$(document).ready(function () {
$.ajaxSetup({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{}",
dataFilter: function (data) {
var msg;
if (typeof (JSON) !== 'undefined' &&
typeof (JSON.parse) === 'function')
msg = JSON.parse(data);
else
msg = eval('(' + data + ')');
if (msg.hasOwnProperty('d')) {
return msg.d;
} else {
return msg;
}
}
});
loadData();
});
This discussion has been closed.
Replies