Uncaught TypeError: Cannot read property 'length' of undefined

Uncaught TypeError: Cannot read property 'length' of undefined

cbraidcbraid Posts: 1Questions: 0Answers: 0
edited May 2013 in Editor
I constantly receive this error everytime i try to Save and Update records using the Editor plugin. I am using JQuery version 1.8.2 with DataTables 1.9.4 and Editor 1.2.3.

Here's my JS code so far
[code]

$(document).ready(function() {
var editor;
editor = new $.fn.dataTable.Editor({
"ajaxUrl": "'.SITE_AJAX.'ajax-custvpns.post.php",
"domTable": "#custVPNList",
"dbTable": "customer_vpns",
"fields": [{
"label": "VPN Friendly:",
"name": "vpnFriendly",
"type": "text"
}, {
"label": "Win Name:",
"name": "vpnWinName",
"type": "text"
}, {
"label": "Win Address:",
"name": "vpnWinAddress",
"type": "text"
}, {
"label": "Win User:",
"name": "vpnWinUser",
"type": "text"
}, {
"label": "Win Password:",
"name": "vpnWinPass",
"type": "password"
}, {
"label": "Win Domain:",
"name": "vpnWinDomain",
"type": "text"
}
]
});

// Create Record
$("a.editor_create").on("click", function (e) {
e.preventDefault();
editor.create(
"Create Customer VPN",
{ "label": "Save", "fn": function () { editor.submit(); } }
);
});

// Edit Record
$("#custVPNList").on("click", "a.editor_edit", function (e) {
e.preventDefault();
editor.edit(
$(this).parents("tr")[0],
"Edit Customer VPN",
{ "label": "Update", "fn": function () { editor.submit(); } }
);
});

// Delete Record
$("#custVPNList").on("click", "a.editor_remove", function (e){
e.preventDefault();
editor.message("Are you sure you want to remove this VPN entry?");
editor.remove(
$(this).parents("tr")[0],
"Delete Customer VPN",
{ "label": "Confirm", "fn": function (){ editor.submit(); } }
);
});

var custVPNTable;
custVPNTable = $("#custVPNList").dataTable({
"bJQueryUI": true,
"sAjaxSource": "'.SITE_AJAX.'ajax-custvpns.src.php",
"bDeferRender": true,
"aoColumns": [
{ "mData": "vpnFriendly" },
{ "mData": "vpnWinName" },
{ "mData": "vpnWinAddress" },
{ "mData": "vpnWinUser" },
{ "mData": "vpnWinPass" },
{ "mData": "vpnWinDomain" },
{
"mData": null,
"sClass": "right",
"sDefaultContent": "Edit / Delete"
}
],
"bProcessing": true,
"sServerMethod": "POST",
"sPaginationType": "full_numbers",
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"iDisplayLength": 25,
"sDom": "<\"H\"<\"span6\"l><\"span6\"fr>>t<\"F\"<\"span6\"i><\"span6\"p>>",
});
});

[/code]

Here's my Ajax code for the processing
[code]
include_once('../../includes/config.php');

$action = isset($_POST['action']) ? $_POST['action'] : NULL;
$table = isset($_POST['table']) ? $_POST['table'] : NULL;
$id = isset($_POST['id']) ? $_POST['id'] : NULL;
$data = isset($_POST['data']) ? $_POST['data'] : NULL;

$oCustomer = new \models\Customer();
if($action == 'create')
{
$insFieldSQL = $insValueSQL = array();
if($data)
{
foreach($data as $field => $value)
{
$insFieldSQL[] = $field;
$insValueSQL[] = $value;
}
}

$insCustSQL = "INSERT INTO ".$table." (".implode(', ',$insFieldSQL).")
VALUES ('".implode("', '",$insValueSQL)."')";

$res = $oCustomer->insertCustDetails($insCustSQL);
echo $res;
}
elseif($action == 'edit')
{
$updFieldSQL = $eFieldList = array();
if($data)
{
foreach($data as $field => $value)
{
$updFieldSQL[] = $field." = '".$value."'";
$eFieldList[] = $field."' => '".$value;
}
}

$updateCustSQL = "UPDATE ".$table."
SET ".implode(', ',$updFieldSQL)."
WHERE vpnID = '".$id."'";

$res = $oCustomer->updateCustDetails($updateCustSQL);
//echo $res;

$eResult = array('id' => $id, 'error' => '', 'fieldErrors' => array(), 'data' => array(), 'row' => array('DT_RowId' => $id,'vpnFriendly' => 'A1 Testing','vpnWinName' => 'A1_Testing_Auto','vpnWinAddress' => '192.168.105.21','vpnWinUser' => 'admin','vpnWinPass' => '','vpnWinDomain' => ''));
echo json_encode($eResult);
}
elseif($action == 'remove')
{
$res = $oCustomer->deleteCustDetails($table,'vpnID',$data[0]);
echo $res;
}
[/code]

When i create / update or delete a record my ajax script runs and updates via the Database but the editor popup stays open with the processing icon spinning. This is when i receive the Uncaught TypeError: Cannot read property 'length' of undefined error. I think this is to do with the ajax response as i don't really know what needs to be sent back once db update is successful.

Any help and advice would be greatly appreciated.
This discussion has been closed.