0
对话形式AJAX的DataTable fnAddData我有一个数据表中定义的文件准备好如下jQuery的距离不工作
$(document).ready(function() {
var oTable = $('#systemgoals').dataTable({});
我有形式的对话,并具有以下功能
buttons: {
"Add System Goal": function() {
var formfilled = true;
$("form#add_systemgoal :text, form#add_systemgoal :file, form#add_systemgoal :checkbox, form#add_systemgoal select, form#add_systemgoal textarea").each(function() {
if($(this).val() === "")
formfilled = false;
});
if(formfilled === true){
$('form#add_systemgoal .error').remove();
var formdata = $('form#add_systemgoal').serialize();
$.ajaxSetup({async: false});
$.ajax({
type: "POST",
url: '/admin/systemgoals/systemgoalupdate?format=html',
data: formdata,
success: function (data) {
var obj = $.parseJSON(data);
if(obj.success){
$(oTable).dataTable().fnAddData([
obj.inserted.goal_id,
obj.inserted.value,
obj.inserted.status,
obj.inserted.points_per_action,
obj.inserted.created,
obj.inserted.due,
obj.inserted.expires ]);
}
}
});
}
的一个按钮ajax是好的形式帖子正确的值回应,但fnAddData返回错误
ReferenceError:oTable未定义
任何意见赞赏
谢谢